animate-components | Elemental components for doing animations in React | Frontend Utils library
kandi X-RAY | animate-components Summary
kandi X-RAY | animate-components Summary
Elemental components for doing animation in React.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of animate-components
animate-components Key Features
animate-components Examples and Code Snippets
Community Discussions
Trending Discussions on animate-components
QUESTION
I have a search form that loads results. Everything gets updated in the Redux state except for the values selected in the form fields.
Lets say the search below shows 3 results. User clicks on result #2 and does not like it. The click the back button but the form state is cleared. How can I avoid this and make sure the form state stays ?
I am storing the results in Redux and able to load that but not sure how to handle state. I dont want to use packages such as redux-form if possible because this is the only place I need to store form state.
The state does not update when I change the selections. This is probably a slight change in code for an expert but I am beginner and this is my first React-Redux app.
Also, when I navigate away from the page, the state that was last stored is not retained. This is probably because of the local state formValues: {}
that I am initializing but without this, there are errors. I tried to delete local state and just use props but it is giving me errors on the select box at this line - value={this.state.formValues['gender']}
Here is the overall code of the component:
...ANSWER
Answered 2018-Aug-17 at 03:28The state does not update when I change the selections
This is because you are not dispatching a Redux action in your handleChange
method, only in your handleSubmit
method. Simply dispatching the appropriate action in handleChange
will resolve this issue.
when I navigate away from the page, the state that was last stored is not retained
This is because the values from before (before you navigate away) will only be kept in the Redux store, while the form fields are populated from the local state of the SearchAdvanced
component.
To solve this one well, you should get rid of your local state entirely. Instead only use the Redux store. Keeping both intact is unnecessary and breaks the 'Single Source of Truth' that Redux is meant for. I recommend you do away with the local state and only update the Redux state and then pass values to the form inputs from the Redux store (props
for the component).
Regarding your note that you tried this, but get errors: you need to change anything like:
QUESTION
I am using a "LOAD MORE" button to show 2 results at a time. In the screenshot below the user clicked LOAD MORE once so it displays all 3 results.
When the user navigates away from the page, and comes back, I want to store the last value of pageNo and use it to display number of results.
This is probably a one line change of code but I cant figure out.
I am using Redux and able to store states such as searchedOnce (boolean). But for this particular state - pageNo, I am not able to apply save the incremented value in Redux. When the user leaves the page and comes back, the state of pageNo changes back to the initial value which is 1. I am expecting this to be 2 because that was the last value store in redux state. I think my dispatch line in loadMoreClick() needs to change.
...ANSWER
Answered 2018-Aug-16 at 20:18Don't use local state for pageNo
. It looks like your component has pageNo
as a prop and as local state. This is confusing for devs, and likely where you're getting tripped up. If this.props.dispatch(setPageNum(this.state.pageNo))
is correctly storing the pageNo
in a reducer, then just rely on this.props.pageNo
. Delete pageNo
from your local state entirely.
Local state is destroyed when your component unmount. And consequently, when the user navigates away and back, the this.state.pageNo
is reset. The pageNo
value stored in redux will not reset when the component unmounts.
Try replacing this.state.pageNo
with this.props.pageNo
. Remember, you can't modify this.props.pageNo
directly. You can only do so through your setPageNum action creator. i.e. this.props.dispatch(setPageNum(this.props.pageNo + 1))
or whatever you'd like to set it to.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install animate-components
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page