AI
Size: a a a
AI
AI
AI
const Buttons = memo(({increment, submit}) => [
<button onClick={submit}>submit</button>,
<button onClick={increment}>submit</button>
]);
function send(stateRef) {
return axios.post('', { value: stateRef.current });
}
function Counter() {
const [state, changeState] = useState(0);
const stateRef = useRef();
useEffect(() => {
stateRef.current = state;
}, [state])
const increment = useCallback(() => changeState(value => value + 1), []);
const submit = useCallback(() => send(stateRef).then(() => changeState(0)), []);
return (
<Fragment>
<Buttons submit={submit} increment={increment} />
</Fragment>
)
}
AI
AI
AI
OJ
AI
VK
OJ
AI
AI
AI
OJ
AI
AI
OJ
AI
AI
AI