Skip to content

Commit

Permalink
Update on "[compiler] Allow functions containing refs to be returned"
Browse files Browse the repository at this point in the history
Summary:
We previously were excessively strict about preventing functions that access refs from being returned--doing so is potentially valid for hooks, because the return value may only be used in an event or effect.

[ghstack-poisoned]
  • Loading branch information
mvitousek committed Aug 16, 2024
2 parents 8b60b37 + a43dfc9 commit ff1a1a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
```javascript
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees

import {useRef} from 'react';

component Foo() {
const ref = useRef();

Expand All @@ -26,6 +28,8 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { c as _c } from "react/compiler-runtime";

import { useRef } from "react";

function Foo() {
const $ = _c(1);
const ref = useRef();
Expand All @@ -48,4 +52,4 @@ export const FIXTURE_ENTRYPOINT = {
```
### Eval output
(kind: exception) useRef is not defined
(kind: ok) "[[ function params=0 ]]"
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees

import {useRef} from 'react';

component Foo() {
const ref = useRef();

Expand Down

0 comments on commit ff1a1a3

Please sign in to comment.