score:2
Accepted answer
looks like you did override your name & age again in mapstatetoprop
function which only state should be returned in the function:
const maptoprop = (state) => {
return {
...state,
// you would nee to remove this overrides
// name: "sagar",
// age: "22"
}
}
score:0
with the updation in @tmhao2005's answer , i updated -
const maptoprop=(state)=>{
return{
...state,
name:state.name==null?"sagar":state.name
//age:"22"
}
}
this started working. all credit to @tmhao2005 , as without his initial answer wont have been reached to this point.
Source: stackoverflow.com
Related Query
- not getting updated state value in react using hooks?
- React Js : Value / State not getting updated
- React - < Input> value is not getting updated on onChange event
- Input type text's value not getting updated while using React JS
- React <Switch> is not getting updated or changing its state
- Method not getting correct useState value despite updating state in React
- React - Date input value not updated to state
- React - ComponentDidMount not getting value from Redux state
- updated state value are not updated inside function in react
- Updated state value is not reflected inside setInterval() in React
- React Hooks Wrapper not getting updated after state change in useEffect
- Why callbacks in react functional component is not reading the updated state value
- why I am not getting updated props value in react
- React State not getting updated properly in SetInterval Methods
- Input element's value in react component is not getting re-rendered when the state changes
- React useCallback hook, not receiving updated dependency state value
- React Hook useCallback not getting updated state when invoked
- React - state not getting updated after a prop being sent from another component
- React component is not getting updated when state changes into the redux
- React input value is not getting updated although value next to it with same variable is
- In react on first time data is getting fetched, when user move to chat with one another user, state value is not getting change
- ReactJs Checkbox value and date not getting updated in state
- React State not getting updated onClick
- Update state on react not getting right value
- State is not getting updated in Function Component using useState in React
- React context state value not updated in Consumer
- React Hook's state not getting updated
- Creating a simple todolist using React Js.Dont know why my state is not getting updated with new todo Item
- once the data has been fetched the state value are not getting updated
- React - State not updated or getting reset to old state
More Query from same tag
- Unable to position navigation bar elements correctly in ReactJS
- How to export one file to NodeJS and ReactJS?
- How to change value of select input which is inside a form balise (ant design)
- How can I remove "net::ERR_NAME_NOT_RESOLVED"?
- How to implement Formik's Field component with Material-Ui Autocomplete for Multi-Select check boxes?
- React and Redux toolkit : loose the state when I want to use filter action
- Remove items from an array, reorder the items, then put it back (reactjs)
- React state, remove item in array after a while
- React Modal close if is clicked outside of content
- Update without page refresh
- render() is not being called on this.setState()
- Meeting multiple conditions that aren’t set simultaneously in componentWillReceiveProps
- Unable to setState on ReactJS component from outside React
- Module not found: Can't resolve 'redux' in node_modules
- How to set moment to empty depending on select
- React component props. How to get the inner object?
- React child prop rendering before parent?
- Prisma Schema not updating properly after adding new fields
- Why can't I call localhost localhost:5000 from localhost:3000 using axios in react
- How to read the value of propTypes of my Button component
- How can I make a MaterialUI form control wider when a value hasn't been selected?
- How to actually initiate a function from another file in React.js
- Syntax problem in media query using styled-components
- Searching through object in React using another object
- Display dynamic PDF from network drive in React App with Node server
- Toggle visibility of two components from buttons inside of them in React
- Form in div element not aligning in one row
- What is the right way to use Ionic Native / Cordova Plugins with Ionic (React) & Capacitor?
- POST http://localhost:3001/[object%20Promise] 404 (Not Found) React Axios
- Testing a Material ui Select component without using testid