main
ts 34 lines 909 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 import {
9 ErrorCategory,
10 getRuleForCategory,
11 } from 'babel-plugin-react-compiler/src/CompilerError';
12 import {normalizeIndent, testRule, makeTestCaseError} from './shared-utils';
13 import {allRules} from '../src/rules/ReactCompilerRule';
14
15 testRule(
16 'no ref access in render rule',
17 allRules[getRuleForCategory(ErrorCategory.Refs).name].rule,
18 {
19 valid: [],
20 invalid: [
21 {
22 name: 'validate against simple ref access in render',
23 code: normalizeIndent`
24 function Component(props) {
25 const ref = useRef(null);
26 const value = ref.current;
27 return value;
28 }
29 `,
30 errors: [makeTestCaseError('Cannot access refs during render')],
31 },
32 ],
33 },
34 );