Files
bun-src/test/bundler/transpiler/react-compiler-fixtures/valid-setState-in-effect-from-ref-array-index.expect.md
T
2026-08-27 21:09:14 +00:00

936 B

Input

// @validateNoSetStateInEffects @enableAllowSetStateFromRefsInEffects @outputMode:"lint"
import {useState, useRef, useEffect} from 'react';

function Component() {
  const ref = useRef([1, 2, 3, 4, 5]);
  const [value, setValue] = useState(0);

  useEffect(() => {
    const index = 2;
    setValue(ref.current[index]);
  }, []);

  return value;
}

export const FIXTURE_ENTRYPOINT = {
  fn: Component,
  params: [],
};

Code

// @validateNoSetStateInEffects @enableAllowSetStateFromRefsInEffects @outputMode:"lint"
import { useState, useRef, useEffect } from "react";

function Component() {
  const ref = useRef([1, 2, 3, 4, 5]);
  const [value, setValue] = useState(0);

  useEffect(() => {
    const index = 2;
    setValue(ref.current[index]);
  }, []);

  return value;
}

export const FIXTURE_ENTRYPOINT = {
  fn: Component,
  params: [],
};

Eval output

(kind: ok) 3