Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion types/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"dependencies": {
"csstype": "^3.0.2"
"csstype": "^3.0.2",
"utility-types": "^3.10.0"
},
"exports": {
".": {
Expand Down
5 changes: 3 additions & 2 deletions types/react/v17/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import * as CSS from 'csstype';
import * as PropTypes from 'prop-types';
import { Interaction as SchedulerInteraction } from 'scheduler/tracing';
import { DeepReadonly } from "utility-types";

type NativeAnimationEvent = AnimationEvent;
type NativeClipboardEvent = ClipboardEvent;
Expand Down Expand Up @@ -918,15 +919,15 @@ declare namespace React {
* @version 16.8.0
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
function useState<S>(initialState: S | (() => S)): [DeepReadonly<S>, Dispatch<SetStateAction<S>>];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a Readonly here suffice for the majority of use cases? I'm mainly concerned about perf here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think DeepReadonly would be preferred to prevent mutating nested members of an object.

// convenience overload when first argument is omitted
/**
* Returns a stateful value, and a function to update it.
*
* @version 16.8.0
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
function useState<S = undefined>(): [DeepReadonly<S> | undefined, Dispatch<SetStateAction<S | undefined>>];
/**
* An alternative to `useState`.
*
Expand Down