immer((set, get) => {
return {
apple: 1,
orange: 2,
total: () => {
return get().apple + get().orange;
}
}}
const { apple, orange, total } = useStore(
useShallow(state => {
return {
apple: state.apple,
orange: state.orange,
total: state.total,
};
}),
);
const appleAdd = () => {
useInquiryOrderEditStore.setState({
apple: apple + 1,
});
};
<div>
app: {apple}, orange: {orange}, total: {total()}
</div>
<div>
<button onClick={appleAdd}>新增</button>
</div>