我有使用两个独立组件的反应代码。单击第一个组件中的按钮时,我隐藏当前组件并显示另一个组件。但我也想将一些值从第一个组件(从INPUTS)传递到第二个组件。请告诉我该怎么做?这是代码:
应用程序.js
import React from 'react';
import { useState } from 'react';
import { FirstSection} from './components/FirstSection';
import { SecondSection} from './components/SecondSection';
function App() {
const [checkSection, setSection] = useState(false);
const showSecondSection= () => setSection(true);
return (
<div className="App">
{checkSection ? <SecondSection /> : <FirstSection onClick={showSecondSection} />}
</div>
);
}
export default App;
第一节.jsx
export function FirstSection({onClick}) {
return(
<>
<input type="text" value="{input1}" />
<input type="text" value="{input2}" />
<button onClick={onClick}>Continue</button>
</>
)
}
第二节.jsx
export function SecondSection() {
return(
<>
<p>{input1}, {input2}</p> <== Сюда я хочу передать данные из первого компонента
</>
)
}
第一节组件
第二部分组件
游戏代码