Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

save previousdata react

You can make use of Redux to achieve the same. What you need to do is to save the form states in redux store rather than the component localState itself

You reducer will look something like

const initialState = {
      name: '',
            color: '',
            description: '',
            beacons: []
}
const BeaconForm = (state = initialState, action) => {
      switch(action.type) {
          case 'UPDATE_BEACON_FORM_VALUE': 
               return {
                    ...state, [action.newVal.key]: action.newVal.value
               }
          default: return state
      }
}

export default BeaconForm
And then have an action

export function updataFormValue(updatedVal) {
       return { type: 'UPDATE_BEACON_FORM_VALUE', newVal: updatedVal}
}
And in the compoennt

handleInputChange(event) {

    var data = {[event.target.name]: event.target.value}
    this.props.updataFormValue(data);

}
Apart from this you need to make your component Redux compatible with connect, mapStateToProps , etc which I assume you already know

And then instead of setting input value from state you will set it from props that youu get from redux store
Comment

PREVIOUS NEXT
Code Example
Javascript :: onclose modal bootstrap 
Javascript :: angular router link 
Javascript :: searc and replace fcc solution 
Javascript :: how to deploy firebase angular 10 
Javascript :: reactjs lifecycle class components 
Javascript :: JavaScript setTimeout js function timer command 
Javascript :: how to run the sonar scanner 
Javascript :: pass props in compound component 
Javascript :: row smaller than the container bootstrap react 
Javascript :: arrow function javascript 
Javascript :: vanilla js http server 
Javascript :: how-to-show-base64-image-in-react 
Javascript :: Update matched key values in two JavaScript objects 
Javascript :: which line will generate a random number between 1 to 10 javascript 
Javascript :: Check if instance is array 
Javascript :: javascript ISO Date Formats 
Javascript :: setinterval() nodejs 
Javascript :: js if condition 
Javascript :: jquery animate transform 
Javascript :: How to clear one property of state in vuex store 
Javascript :: adb.exe: more than one device/emulator react native 
Javascript :: d3 v6 
Javascript :: Javascript using for loop to loop through an array 
Javascript :: javascript bool 
Javascript :: chain id 
Javascript :: mogoosejs 
Javascript :: URLSearchParams for query params 
Javascript :: javascript on focus 
Javascript :: javascript execute function after async 
Javascript :: setting live reload sublime text 3 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =