FormidableLabs / freactal

Clean and robust state management for React and React-like libs.
MIT License
1.65k stars 46 forks source link

Question: Initialize state to props? #39

Closed alexknipfer closed 7 years ago

alexknipfer commented 7 years ago

What's the best way to initialize state to a specific prop value? Or, how do I access props within initialState? Obviously, using React's state you would just set the initial state to this.props.value, but what is the correct way to do so with freactal?

For example:

const wrapComponentWithState = provideState({
  initialState: () => ({
    testValue:   //Initialize to prop value here
  })
})
aweary commented 7 years ago

Freactal passes props and context to initialState, so it would just look like:

const wrapComponentWithState = provideState({
  initialState: (props) => ({
    testValue:   props.value
  })
})
alexknipfer commented 7 years ago

Oh, perfect! Thanks so much!