I'm new to React and I'm stuck with something.
I have 3 components, Home, UserForm and Input, they're nested as described. I need to have the values of the input as the user types on the home component. I can't get it to work.
I need help!
home.jsx
import React from 'react';
import UserForm from '../components/UserForm';
import './Home.scss';
export default function Home() {
return (
<div className="home-container">
<div className="card-container">
</div>
<div className="description-container">
<div className="form-container">
<UserForm />
</div>
</div>
</div>
)
}
UserForm.jsx
import React from 'react';
import Input from './Input';
export default function UserForm(props) {
return (
<div className="user-form">
<form>
<Input
placeholder="Nome a ser impresso" />
<Input placeholder="E-mail" type="email" />
</form>
</div>
)
}
Input.jsx
import React, { useState } from 'react';
import './Input.scss';
export default function Input(props) {
const [inputVal, setInputVal] = useState('');
function listenToInput(e) {
setInputVal(e.target.value);
}
return (
<div className="input-holder">
<input
type={props.type || 'text'}
placeholder={props.placeholder}
value={inputVal}
onChange={listenToInput}/>
</div>
)
}