How to transfer props from one sibling to another, please?
In main app I have only 2 siblings:
Input:
import React from "react";
const Input = () => {
return (
<>
<label htmlFor="name">Full Name</label>
<input type="text" id="name" placeholder="TheDareback" />
<label htmlFor="job">Job Title</label>
<input type="text" id="job" placeholder="Frontend Developer" />
</>
);
};
export default inputDetails;
Preview:
import React from "react";
const Preview = () => {
return (
<>
<table>
<thead>
<tr>
<th>{/* here I need a Full Name from the input */}</th>
<th>{/* here I need a Job Title from the input*/}</th>
</tr>
</thead>
</table>
</>
);
};
export default Preview;
I tried to add useEffect to Preview to read the value of each input.
for example
const name = document.querySelector("#name");
const [inputName, setInputName] = useState("TheDareback");
useEffect(() => (name.value ? setInputName(name.value) : null));
But I'm still getting an error:
Preview.js:9 Uncaught TypeError: Cannot read properties of null (reading 'value')
Is it possible to run useEffect only during the second rendering? Alternatively, is there another option than to move the props directly from Input.js where would I create a handler for each onChange in input?
Thank you very much for heading in the right direction.