Add React props hook.#1523
Merged
Merged
Conversation
This is useful for a descendant 'Component' to react to changes in its
parent 'Component'. Currently, hooks just alter the child 'View',
without invoking the 'update' function. Like `mount` / `unmount`, the
`props` phase allows one to "hook" into `props` as they alter over time.
This further aligns miso w/ React specification parity. The `props`
phase is an action that executes post `Component` draw. It receives
both old props and new props as arguments.
Sharing should be preserved between old and new props.
```haskell
-- defaults to 'Nothing'
-- | Interface proposal
props :: Maybe (props -> props -> action)
-- ^ old ^ new
-- | Example 'Action'
data Action = PropsChanged ButtonProps ButtonProps
-- | Example usage
test :: Component parent ButtonProps model Action
test = myComponent { props = Just PropsChanged }
```
- [x] Extend 'Component' to receive `props` phase callback function
- [x] Add `prevComponentProps`
- [x] Extend `ComponentState` with `_componentPropsPhase`
- [x] Add `prevComponentProps` `Lens`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
propshook 🪝This is useful for a descendant
Componentto react to changes in its parentComponent. Currently, hooks just alter the childView, without invoking theupdatefunction. Likemount/unmount, thepropsphase allows one to "hook" intopropsas they alter over time and process anactionin response to these changes.This further aligns miso w/ React specification parity. The
propsphase is an action that executes postComponentdraw. It receives both old props and new props as arguments.Sharing should be preserved between old and new props.
propsphase callback functionprevComponentPropsComponentStatewith_componentPropsPhaseprevComponentPropsLens.The analog in React would be to track the previous props manually using a hook (
useRef).