Skip to content

Commit ec3eabb

Browse files
Caleb Kemperalfonsogarciacaro
authored andcommitted
Marked setState(s: 'S) as Obsolete as per #104, with message to use setState(updater: 'S->'P->'S) instead.
1 parent b79c433 commit ec3eabb

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/Fable.React/Fable.Import.React.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module React =
9191
/// Think of setState() as a request rather than an immediate command to update the component. For better perceived performance, React may delay it, and then update several components in a single pass. React does not guarantee that the state changes are applied immediately.
9292
/// setState() does not always immediately update the component. It may batch or defer the update until later. This makes reading this.state right after calling setState() a potential pitfall. Instead, use componentDidUpdate or a setState callback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied. If you need to set the state based on the previous state, read about the updater argument below.
9393
/// setState() will always lead to a re-render unless shouldComponentUpdate() returns false. If mutable objects are being used and conditional rendering logic cannot be implemented in shouldComponentUpdate(), calling setState() only when the new state differs from the previous state will avoid unnecessary re-renders.
94+
[<Obsolete("This overload is unsafe because it forces use of this.state. Use setState(updater: 'S->'P->'S) instead.")>]
9495
[<Emit("$0.setState($1)")>]
9596
member x.setState(value: 'S): unit = x.state <- value
9697

0 commit comments

Comments
 (0)