immer 使用场景举例·

import { produce, enableES5 } from 'immer';

1、

if (data) {
        this.setState(
          produce((draft) => {
            draft.dataArry.push(data);
            draft.loading = false;
          }),
        );

2、

 constructor(props: any) {
    super(props);
    this.state = {
      a: { b: 1 },
    };
  }
  onClick = () => {
    this.setState(
      produce((draft: any) => {
        _.set(draft, 'a.b', 2);
      }),
    );
  };

 3、

 constructor(props: any) {
    super(props);
    this.state = {
      a: { b: 1 },
    };
  }
  onClick = () => {
    this.setState(
      produce((draft: any) => {
        _.set(draft, 'a.b', 2);
      }),
    );
  };

 

posted on 2023-08-07 15:15  漫思  阅读(7)  评论(0编辑  收藏  举报

导航