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); }), ); };
漫思