score:4
Accepted answer
class CompleteProfile extends Component {
state = {
completeProfile: false,
}
componentDidMount(){
let { dispatch, session } = this.props
dispatch(getMandatoryFields(session.username))
}
componentDidUpdate() {
console.log(
'this.props.mandatory_fields.updateNeeded -- ' +
this.props.mandatory_fields.updateNeeded
)
if (this.props.mandatory_fields.updateNeeded !== false) {
this.setState({
completeProfile: this.props.mandatory_fields.updateNeeded,
})
}
}
...
...
....
const mapStateToProps = state => ({
mandatory_fields: state.User.mandatory_fields,
session: state.User.session,
})
export default connect(mapStateToProps)(CompleteProfile)
score:1
componentDidUpdate(prevProps) {
let { dispatch, session } = this.props
dispatch(getMandatoryFields(session.username))
console.log(
'this.props.mandatory_fields.updateNeeded -- ' +
this.props.mandatory_fields.updateNeeded
);
if (!prevProps.mandatory_fields.updateNeeded && this.props.mandatory_fields.updateNeeded) {
this.setState({
completeProfile: this.props.mandatory_fields.updateNeeded,
})
}
}
Source: stackoverflow.com
Related Query
- React - ComponentDidMount not getting value from Redux state
- Redux store state from React component's props does not reflect redux store's state value
- React hooks useState getting diferrent value from redux state
- Input field not updating from redux state but displays value on console.log in react
- React + Redux - Input onChange is very slow when typing in when the input have a value from the state
- React app componentDidMount not getting props from parent
- React Redux Axios: POST Request not receiving credentials from redux state
- ComponentDidMount not getting called after redux state update?
- Method not getting correct useState value despite updating state in React
- React Hooks and Redux - trouble getting value from action creator
- select option from dropdown using API and get that selected value but i am getting last value which i have not selected in react
- React Router Link with params not reloading page with new data from componentDidMount and Redux axios data fetching
- React router private route not getting props from state (e.g. authentication state)
- Value not getting passed from child to parent component in React
- State not updating on removing value from array in React JSX funcntional component
- rule validation not triggered on input field when value is changed from React state
- React Redux store not updating on delete of an item from state
- Input element's value in react component is not getting re-rendered when the state changes
- How to set defaultChecked getting value from state React Functional Component Checkbox (React - Hooks)
- 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
- Redux reducer not updating prop value in React component from dispatch outside React components
- In react on first time data is getting fetched, when user move to chat with one another user, state value is not getting change
- SetAll from CreateEntityAdapter do not set the state with react redux toolkit
- not getting updated state value in react using hooks?
- I am trying to load data from redux store on click and updating the state, but the data from state is not getting updated on the click
- Value of Select Tag from state dom is not changing in react
- React not updating state from redux
- React Redux - Getting state to component - Uncaught TypeError: users.map is not a function
- React JS (Form Update Not Working) - How to set state immediately after getting data from API using mapDispatchToProps?
More Query from same tag
- React and Material-UI: how to structure application with multiple pages
- Await is only allowed within async functions - webpack, redux thunk
- React Rainbow UI example missing theme
- getBoundingClientRect returning same value in Chrome
- Get data From IonModal In Ionic React
- How to use my react component PlaceInput to achieve place autocomplete in the menu input box?
- Clash between functions, api not hitting
- The cursor does not appear in the <select> element on scss
- react-explode library gives "Invalid hook call" error
- How To Render <Componet/> or Jsx multiple times based on Click or Form Submit
- How can I change animation-timing-function for Slide component in MaterialUi react
- Props are not passed down to the child component - redux-form/react
- Link param doesn't render in JSX (react)
- Cursor jumps to end when input value comes from "unstated" provider
- How does React provide independent contexts for subtrees?
- What is `useState(null)[1]` in React hooks?
- where is the "this.props" defined?
- Nextjs dynamic routing exclude
- I cant seem to use store of React.createContext in typescript
- React POST 422 (Unprocessable Entity)
- Toggle boolean on state in react
- How not to pass down props using Redux?
- React & SVG: HTML inside foreignobject not rendered
- How to change color of div that's selected and others be same?
- How do I set state from within a fetch in ReactJS?
- GraphQLList and react
- How to hide navbar in login page in react router
- React-router error - 'Cannot call method 'getRouteAtDepth' of undefined'
- Add a point to list of points and rerender on map
- useState and callback function