Skip to content

Commit 8c4fe53

Browse files
committed
Add react precallgraphstep useRef
1 parent a0d2005 commit 8c4fe53

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added PreCallGraphStep flow model for React's `useRef` hook.

javascript/ql/lib/semmle/javascript/frameworks/React.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,25 @@ private class UseStateStep extends PreCallGraphStep {
612612
}
613613
}
614614

615+
/**
616+
* Step through a `useRef` call.
617+
*
618+
* It returns a pair of the initial state, and an object with a single property (current) potentially containing an input value.
619+
*
620+
* For example:
621+
* ```js
622+
* const inputRef1 = useRef(initialValue);
623+
* ```
624+
*/
625+
private class UseRefStep extends PreCallGraphStep {
626+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
627+
exists(DataFlow::CallNode call | call = react().getAMemberCall("useRef") |
628+
pred = call.getArgument(0) and // initial state
629+
succ = call.getAPropertyRead("current")
630+
)
631+
}
632+
}
633+
615634
/**
616635
* A step through a React context object.
617636
*

0 commit comments

Comments
 (0)