Files
react/compiler/crates/react_hermes_parser/tests/fixtures/inadvertent-mutability-readonly-lambda.js
2024-04-02 16:49:31 -07:00

14 lines
430 B
JavaScript

function Component(props) {
const [value, setValue] = useState(null);
// NOTE: this lambda does not capture any mutable values (only the state setter)
// and thus should be treated as readonly
const onChange = (e) => setValue((value) => value + e.target.value);
useOtherHook();
// x should be independently memoizeable, since foo(x, onChange) cannot modify onChange
const x = {};
foo(x, onChange);
return x;
}