Equivalent to react's setState callback?
See original GitHub issueI have a need to execute arbitrary logic only after a state change has been applied. In react
land, I can accomplish this by running setState(state, cb)
. Based on my extremely limited hyperapp
experience, this appears to be impossible since, in order to update state, an action must return
.
Is there already a means of doing what I want in hyperapp
? If not, is there any interest in adding this feature?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to use `setState` callback on react hooks - Stack Overflow
setState method is asynchronous, and as a matter of fact, it does not return a promise. So In cases where we want to...
Read more >How to Use the setState Callback in React - Upmostly
To perform an action in a React component after calling setState, such as making an AJAX request or throwing an error, we use...
Read more >How to Use callBack With setState in React - CODERSERA
setState () enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the...
Read more >React setState calback with Functional Component - Medium
useState returns the current state and a function to update it. But this function updates the value in an asynchronous way.
Read more >Provide callback to useState hook like setState - LinkedIn
In React functional components, a callback function for anything can be implemented using the useEffect hook. We will be using the same to ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jpodwys FWIW: I sometimes make a generic
reduce
action, to use, for example as a callback in promises.… it’s along the lines of your
setState
action, but without the actual state-setting part 😉 It suffers from the same problem though: you have to repeat it in every namespace where you’ll need it, if you’re using nested actions. But since it’s not a very common need, and the action is so small, it’s no big deal.Oh right, I’m not using nested state/actions so I hadn’t considered this. Good catch. Your solution makes sense, I’ll give it a go!