@douyinfe/semi-ui
Version:
A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.
19 lines (18 loc) • 494 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useStateWithGetter;
var _react = require("react");
// https://github.com/facebook/react/issues/14543
function useStateWithGetter(initial) {
const ref = (0, _react.useRef)();
const [state, setState] = (0, _react.useState)(initial);
ref.current = state;
const set = value => {
ref.current = value;
setState(value);
};
const get = () => ref.current;
return [state, set, get];
}
;