Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,10 +185,7 @@ fn join_ref_access_ref_types(a: &RefAccessRefType, b: &RefAccessRefType) -> RefA
loc: None,
ref_id: None,
},
(_, RefAccessRefType::RefValue { .. }) => RefAccessRefType::RefValue {
loc: None,
ref_id: None,
},
(_, RefAccessRefType::RefValue { .. }) => b.clone(),
(RefAccessRefType::Ref { ref_id: a_id }, RefAccessRefType::Ref { ref_id: b_id }) => {
if a_id == b_id {
a.clone()
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@

## Input

```javascript
// @validateRefAccessDuringRender
functionComponent({cond}) {
constref=useRef(null);
constx= cond ? ref :ref.current;
return<Foo value={x} />;
}

```


## Error

```
Found 1 error:
Error: Cannot access refs during render
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef).
error.invalid-ref-value-phi-with-ref.ts:4:25
2 | function Component({cond}) {
3 | const ref = useRef(null);
> 4 | const x = cond ? ref : ref.current;
| ^^^^^^^^^^^ Cannot access ref value during render
5 | return <Foo value={x} />;
6 | }
7 |
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
// @validateRefAccessDuringRender
function Component({cond}) {
const ref = useRef(null);
const x = cond ? ref : ref.current;
return <Foo value={x} />;
}
Loading