You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
304 B
JavaScript
18 lines
304 B
JavaScript
"use strict";
|
|
|
|
const React = require("react");
|
|
|
|
module.exports = function useStateRef(initialState) {
|
|
let [ state, setState ] = React.useState(initialState);
|
|
let ref = React.useRef(initialState);
|
|
|
|
return [
|
|
state,
|
|
(newState) => {
|
|
ref.current = newState;
|
|
setState(newState);
|
|
},
|
|
ref
|
|
];
|
|
};
|