mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
@types/react: Update React.Component setState
Allow setState to accept an updater which is null or is a function that may return null. In React 16, passing null to setState or returning null from the updater function does not cause an update.
This commit is contained in:
Vendored
+1
-1
@@ -284,7 +284,7 @@ declare namespace React {
|
||||
// See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
|
||||
// Also, the ` | S` allows intellisense to not be dumbisense
|
||||
setState<K extends keyof S>(
|
||||
state: ((prevState: Readonly<S>, props: P) => (Pick<S, K> | S)) | (Pick<S, K> | S),
|
||||
state: ((prevState: Readonly<S>, props: P) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
|
||||
callback?: () => void
|
||||
): void;
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ class SetStateTest extends React.Component<{}, { foo: boolean, bar: boolean }> {
|
||||
this.setState({ foo: true });
|
||||
this.setState({ foo: true, bar: true });
|
||||
this.setState({});
|
||||
this.setState(null);
|
||||
this.setState({ foo: true, foo2: true }); // $ExpectError
|
||||
this.setState(() => ({ foo: '' })); // $ExpectError
|
||||
this.setState(() => ({ foo: true }));
|
||||
@@ -103,6 +104,7 @@ class SetStateTest extends React.Component<{}, { foo: boolean, bar: boolean }> {
|
||||
this.setState(() => ({ foo: '', foo2: true })); // $ExpectError
|
||||
this.setState(() => ({ })); // ok!
|
||||
this.setState({ foo: true, bar: undefined}); // $ExpectError
|
||||
this.setState(prevState => (prevState.bar ? { bar: false } : null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user