diff --git a/README.md b/README.md index 173ab24..7172f08 100644 --- a/README.md +++ b/README.md @@ -770,6 +770,31 @@ export default () => ( > https://reactjs.org/docs/hooks-intro.html +#### - useState + +> https://reactjs.org/docs/hooks-reference.html#usestate + +```tsx +import * as React from 'react'; + +type Props = { initialCount: number }; + +export default function Counter({initialCount}: Props) { + const [count, setCount] = React.useState(initialCount); + return ( + <> + Count: {count} + + + + + ); +} + +``` + +[⇧ back to top](#table-of-contents) + #### - useReducer Hook for state management like Redux in a function component. diff --git a/README_SOURCE.md b/README_SOURCE.md index fa2a059..044048a 100644 --- a/README_SOURCE.md +++ b/README_SOURCE.md @@ -313,6 +313,14 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ > https://reactjs.org/docs/hooks-intro.html +#### - useState + +> https://reactjs.org/docs/hooks-reference.html#usestate + +::codeblock='playground/src/hooks/use-state.tsx':: + +[⇧ back to top](#table-of-contents) + #### - useReducer Hook for state management like Redux in a function component. diff --git a/playground/src/hooks/use-state.tsx b/playground/src/hooks/use-state.tsx new file mode 100644 index 0000000..3a7413a --- /dev/null +++ b/playground/src/hooks/use-state.tsx @@ -0,0 +1,15 @@ +import * as React from 'react'; + +type Props = { initialCount: number }; + +export default function Counter({initialCount}: Props) { + const [count, setCount] = React.useState(initialCount); + return ( + <> + Count: {count} + + + + + ); +}