-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Hi, I'd like to discuss an use case for which I think the new lifecycle methods won't help demonstrating how it seems to me like a bad move to deprecate componentWillUpdate (or prefix it with UNSAFE_).
I have some sort of client-side router that uses the history API to change the query search to implement some sort of state-machine for a given component. Think of some UsersManagement component that could render actions such as list, edit and display actions. It has an "action" state and render() will dispatch to the proper method depending on what is the current action.
When there's an action change, some initialization is required and I'd like to reset some other relevant states. Currently, the only way I can think of implementing that is to store the previous "action" state in some instance property and compare the current action with the previous one in render(). When they are different I'd perform the changes to the other state attributes in-place since it's already too late to call setState() from render().
Even componentWillUpdate() is not ideal for that since I can't call setState from it either, but at least I wouldn't have to store the previous "action" state myself. With componentWillUpdate() I'd be able to compare the previous action state with the next one and modify the relevant state changes in-place before render is called, which seems like a bit cleaner approach.
I feel that something is missing in React and that it should be possible to react to state changes and perform further state changes before rendering without much hack. State machines should be possible even without something like Redux. Am I missing something obvious while trying to implement a state machine?