You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am unable to use the ref attribute on some components where I need it, such as the Select component (because it's an input) and the ErrorSummary component (to focus on it when it appears). If I try to use the ref attribute I get the following React error:
index.js:1 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
The Input component achieves ref forwarding this by including an innerRef attribute to forward the ref to the input. I think this should work on the other components too (and I presume all input-like components should do this)?
The text was updated successfully, but these errors were encountered:
import{Input,Select}from'nhsuk-react-components';import{useRef}from'react';constMyComponent=()=>{constinputRef=useRef(null);constselectRef=useRef(null);// inputRef is a prop on the NHS input component and correctly forwards the ref to the underlying input element.// The NHS select component lacks an inputRef, and trying to use the normal ref is not allowed by React (see warning in post). return(<><InputinputRef={inputRef}/><Selectref={selectRef}/></>);};exportdefaultMyComponent;
Hi, I am unable to use the
ref
attribute on some components where I need it, such as the Select component (because it's an input) and the ErrorSummary component (to focus on it when it appears). If I try to use theref
attribute I get the following React error:The Input component achieves ref forwarding this by including an
innerRef
attribute to forward the ref to the input. I think this should work on the other components too (and I presume all input-like components should do this)?The text was updated successfully, but these errors were encountered: