File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
semmle/javascript/frameworks Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ category : minorAnalysis
3+ ---
4+ * Added PreCallGraphStep flow model for React's ` useRef ` hook.
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments