获得徽章 0
export const useContextState = (defaultValue) => {
const [control, setControl] = useState(() => {
const state = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
state.useContextStateType = '1';
const update = () => {
setControl({
state,
update,
});
};
const stateControl = {
state,
update,
};
return stateControl;
});
return control;
};


const { state, ...stateControl } = useContextState({
isPreview: false,
handlePreview(show) {
this.isPreview = show;
stateControl.update();
},
});
react中用这种方式来控制状态有没有什么问题。
展开
评论
赞了这篇沸点
#码上掘金# 我刚刚在码上掘金创作了一段代码,欢迎来体验下 code.juejin.cn
评论
前端开发
前端开发
下一页