我想将一个变量“用户名”从兄弟 1 组件传递给兄弟 2 组件并在那里显示。
Sibling1 组件:
'''
const sibling1 = ({usernameData}) => {
const [username, setUsername] = useState(""); // i want to pass the username value i get from input to sibling2 component
const handleChange = event => {
setUsername(event.target.value);
};
return (
<Form.Input
icon='user'
iconPosition='left'
label='Username'
onChange={handleChange}
/>
<Button content='Login' onClick={handleClick} />
)}
export default sibling1;
'''
Sibling2 组件:
'''
export default function sibling2 () {
return (
<h1> Here is where i want to display it </h1>
}
'''