Questions tagged [react-state-management]
637 questions
2
votes
5 answers
Easy way to check if array of objects exists in array of objects before setting state React JS
Consider the following:
this.setState({
validations: [...this.state.validations, ...validations]
}, () => {
// ... Do something
});
Where I am doing: [...this.state.validations, ...validations] validations is an an array of…

TheWebs
- 12,470
- 30
- 107
- 211
2
votes
2 answers
Redux: How to manage conflicting state across routes?
In my application, on route1 I get a list of items from an api call. The component is connected and the items are saved in redux store and passed to the component as props. Now, on route2 I again need this list of items.
For now, i am fetching the…

gaurav5430
- 12,934
- 6
- 54
- 111
2
votes
1 answer
How can I affect the state of just one individual component(card) when i have multiple versions of that component?
Current situation:
I have a card component called LockedCard.
The LockedCard is rendered to the page by being mapped using stored database information. It is on Home.js that these multiple cards exist.
So it is rendered to the page as multiple…

Haydn Neese
- 21
- 2
2
votes
1 answer
How to access state with Context API
I'm using context API for state management in a React application and I'm looking for a way to access state in a stateless function from my Provider class.
I'm familiar with wrapping the Consumer tags around the JSX inside render() but in this case,…

learnerforlife
- 189
- 1
- 3
- 15
2
votes
4 answers
Lifting State with hooks (from a mapped array)
I'm confused about how I'm supposed to raise events from a child component using hooks (or stateless components rather). Maybe I'm thinking too much. Or not enough! I have built a simple example illustrating my confusion.
Say we have a parent…

Jacob
- 31
- 1
- 7
2
votes
0 answers
How can I render my posts with my custom WordPress Gutenberg block by category?
I have been trying to create a Gutenberg block that displays a list of categories as checkboxes on my WordPress edit pages, and then displays on the frontend page a list of posts that are linked to the selected categories.
I have successfully added…

Joshua Waheed
- 277
- 4
- 16
2
votes
2 answers
ReactJS iterate through state array with dynamic key with its data
I have a array like:
"data": {
"key1": {
"key_val1": "data1",
"key_val2": "data2",
"key_val3": "data3",
"key_val4": "data4",
},
"key2": {
"key_val1": "data1",
"key_val2": "data2",
…

Reema Parakh
- 1,347
- 3
- 19
- 46
2
votes
1 answer
Manage State when checkbox is checked/unchecked - React
In my react application a user enters a keyword and gets a list of results. I am trying to implement filters on these results. Below is the screenshot of filters.
Here is my state
class SearchResultsPage extends React.Component{
…

Siddharth Sinha
- 578
- 2
- 15
- 35
2
votes
1 answer
How to dynamically get state array name React
How can I dynamically set the name of the array in state, to get it from state.
onCheckBoxItemClickList(e, value, path) {
console.log(e.target.checked)
if (e.target.checked) {
//append to array
this.setState({
…

Andrew Irwin
- 691
- 12
- 40
2
votes
1 answer
accessing the state outside the class - Reactnative - this.setState is not a function
I am using custom floating text labels which are outside the class and I want to set the state within it. how can I do it please
I have two floating text fields when I click the button I want to set the state to the entered values in the input text…

BRDroid
- 3,920
- 8
- 65
- 143
2
votes
1 answer
Component not re rendering even after calling the setState
I have a react component in which user can upload Image and he's also shown the preview of uploaded image. He can delete the image by clicking delete button corresponding to Image. I am using react-dropzone for it. Here's the code:
class UploadImage…

uneet7
- 2,925
- 7
- 24
- 41
2
votes
2 answers
Setting state from axios response and using it in render
I have this current situation in react where the state is not getting set and if set cannot be used in render.
componentDidMount() {
axios.get(`url`)
.then(function(response){
const test = response.data;
…

SHIKHAR SINGH
- 419
- 6
- 17
2
votes
1 answer
React and Redux: Using state or refs?
I'm currently teaching my self Redux. For this purpose I created a simple Todo application. Now on this application I'm currently at the process of using dispatch() to put a todo into my store. This is a question about your opinion. I want to avoid…

J. Hesters
- 13,117
- 31
- 133
- 249
2
votes
1 answer
Should I be using React State for user-interactions (to toggle visibility classes)?
I am developing a UI library and some of my components change their "state" based upon some interaction from the user.
For example, a user clicks on an accordion panel's title which causes the accordion panel to open and become visible. This state…

ESR
- 1,669
- 1
- 18
- 22
1
vote
1 answer
How do I manage the complex state of a list of components? (Nextjs/ReactJS)
I have a form that I use to create a new recipe with. This form contains a list of ingredients a user can add to and delete from.
It looks like this:
I have an Ingredient Component which is just the quantity, unit, and title input fields. What I'm…

Saif eldeen Adel
- 318
- 3
- 15