RFC: Propose `React.useStateValue`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- react
- Domain
- frontend
Research direction
Start by reading src/React.re around the existing React.useState binding and review the referenced PR 426 and issue 402. Compare the proposed useStateValue API and its useReducer-based approach, then establish a decided API and acceptance criteria before implementation; the issue currently asks for feedback rather than defining done.
Written by the indexing model from the issue text.
Description
I want to re-born this PR https://github.com/reasonml/reason-react/pull/426 but with another approach.
Currently React.useState is a weird API https://github.com/jchavarri/reason-react/blob/6ecf6ee6fdb4412114de9eacba1b3adc517eb387/src/React.re#L116-L121 since expects the initial value to be computed once.
Most codebases I have seen there's a binding that fixes this specific issue. Maybe in a different fashion. I think similarly as @jchavarri where a hook that only holds the value matches 1-to-1 to the JS usage.
Internally at @ahrefs we don't use a binding (and therefore it might be unsafe as @rickyvetter suggest). Instead, we implement useState with a dummy useReducer (but it's not a "zero-cost" binding and is exactly the same implementation as React.js https://github.com/reasonml/reason-react/issues/402)
let useStateValue = initial => {
useReducer((_ignored, newState) => newState, initial);
};
With the interface:
let useStateValue: 'state => ('state, 'state => unit)
I'm opening this PR to gather some feedback if it make sense to add it.
- Dominant language
- Reason
- Stars
- 3.3k
- Forks
- 344
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reasonml/reason-react
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
reasonml/reason-react#892 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
reasonml/reason-react#769 · 4 comments · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
reasonml/reason-react#753 · 1 comment ·
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
reasonml/reason-react#717 · 1 comment ·
-
ppx RFC
Difficulty 5/5 Over a week Newbie friendliness 20/100
reasonml/reason-react#637 · 3 reactions ·
All issues in reasonml/reason-react
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
tvOS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bvaughn/react-resizable-panels#751 · 1 comment ·
-
www.wiwo.de OpenN: AdGuard Browser Extension P3: Medium T: Annoyance
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AdguardTeam/AdguardFilters#242026 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 92/100