Hi I am creating an app where a user can search for a book and put it on a shelf depending on which shelf the user clicks on. Currently the user can type a query and many results can get displayed. The user can open a dropdown on a book and click on a shelf (in the dropdown) to select
Tag: state
Same function called in different buttons and both are giving different output in Reactjs, javascript?
This is my code And I created seperate button and passed the same function ‘viewPage’ as a handler. But When I clicked the button both are showing different results, the button I declared in table is giving me only initial state as output, but the other button is giving correct updated state. So I am confused by its working. So
React State only updates when setting a useless state variable along with the necessary state variable
State is defined like so: In this case, id is totally useless. Don’t need it in my app at all. However, if I try to update items, the state variable doesn’t change and the UI doesn’t reload, unless I also update id: Why is setId necessary here? What is it doing that setItems isn’t? Answer The reason is because setState
handling mutliple inputs using redux
I have react hooks section in which user can edit input fields, there are hundreds of inputs that is why I need to use redux (newbie to redux though), Live demo on codesandbox: demo so far I have this and here is setting js where I have input fields Expected results: Just when the user types in inputs eg first
Material-UI Select doesn’t update after onChange
I’ve seen this problem about all around the web but nothing could come short of giving me a valid explanation. I’m using Material-UI Select and the good ol’ setState(…) from React (not hooks though) My component is composed essentially of those lines : And my problem is that my Select component dosen’t update its value after selecting another option. So
having n states in react, assuming that n won’t be received in props
How could I have n states in a React component Assuming that the component won’t receive this n value in any props, is something that it will get from a database Using useState will create the state, setState for each pair, but I need n pairs Rafael Answer JavaScript arrays doesn’t have a fixed length. You can do something like
Set initial class variable from axios request in React
When i call this function it updates the array questions in state and array initialQuestions variable in constructor. The state questions represents the values form inputs. The inputs are handled in child component with this code setQuestions is passed in props as setQuestions={(state) => this.setState({ questions: state })} So when i change the value of inputs the onChange function is
Why is my setState not working when passed as an argument to a function?
For the function fetchApiAndSetStateForWrongGuesses() I pass it two parameters called randNum and wrongGuess. randNum is just a number but wrongGuess is supposed to be a state. The problem is that when I pass wrongGuess to the function fetchApiAndSetStateForWrongGuesses() the setState doesn’t works. By the time it hits the console.log it just prints out an empty string because thats what the
Mutate Vuex array passed in the payload
What’s the technical difference between next two approaches? Example is trivial but when I have huge nested objects, I need to pass lots of IDs in order to find desired object inside the mutation. In second example I pass an array and just mutate it. Again, technically in both examples we invoke the same push method. Am I right? Should
Why React Component unmounts on each useEffect dependency change?
I am trying to learn React by building a web application. Since I want to learn it step by step, for now I don’t use Redux, I use only the React state and I have an issue. This is my components architecture: As you can see, I have the main file called App.js, in the left side we have the