Skip to content
Myr

docs: Update example-setstate.mdx (#829)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixed writing mistakes.

authored by SyedTayyabUlMazhar · committed by GitHub · parent 16a3d0f · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:website/docs/example-setstate.mdx+2 added-2 removed
31 unmodified lines
32</details>3334## useState + Immer3536The `useState` hook assumes any state that is stored inside it is treated as immutable. Deep updates in the state of React components can be greatly simplified as by using Immer. To following example shows how to use `produce` in combination with `useState`, and can be tried on [CodeSandbox](https://codesandbox.io/s/immer-usestate-ujkgg?file=/src/index.js).36The `useState` hook assumes any state that is stored inside it is treated as immutable. Deep updates in the state of React components can be greatly simplified as by using Immer. The following example shows how to use `produce` in combination with `useState`, and can be tried on [CodeSandbox](https://codesandbox.io/s/immer-usestate-ujkgg?file=/src/index.js).3738```javascript39import React, { useCallback, useState } from "react";40import produce from "immer";
38 unmodified lines
79```8081## useImmer8283Since all state updaters follow the same pattern where the update function is wrapped in `produce`, it is also possible to simply the above by leveraging the [use-immer](https://www.npmjs.com/package/use-immer) package that will wrap updater functions in `produce` automatically:83Since all state updaters follow the same pattern where the update function is wrapped in `produce`, it is also possible to simplify the above by leveraging the [use-immer](https://www.npmjs.com/package/use-immer) package that will wrap updater functions in `produce` automatically:8485```javascript86import React, { useCallback } from "react";87import { useImmer } from "use-immer";
152 unmodified lines