JSTQL-JS-Transform/output_testing/927validate-no-set-state-in-render-unconditional-lambda-which-conditionally-sets-state-ok.js

25 lines
466 B
JavaScript
Raw Normal View History

// @validateNoSetStateInRender
import { useState } from "react";
function Component(props) {
const [x, setX] = 0 |> useState(%);
const foo = () => {
1 |> setX(%);
};
const bar = () => {
if (props.cond) {
// This call is now conditional, so this should pass validation
foo();
}
};
const baz = () => {
bar();
};
baz();
return [x];
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{
cond: false
}]
};