A ref on your own component needs forwardRef to reach a DOM node.
Acceptance criteria
- 1.Reading should show Ada.
A ref on your own component needs forwardRef to reach a DOM node.
function Field(props) { return <input defaultValue="Ada" /> } function App() { const inputRef = React.useRef(null) const [msg, setMsg] = React.useState("") return ( <div> <Field /> <p id="value">{msg}</p> <button id="read" onClick={() => setMsg(inputRef.current ? inputRef.current.value : "no ref")}>read</button> </div> ) } const root = ReactDOM.createRoot(document.getElementById("root")) root.render(<App />)
Output ready when you are
Press Run to render your code, or Submit to validate your solution.