<ClientProfile /> 是一個彈出組件,我試圖將 {user.id} 傳遞給它
這是我的openClinetProfile功能,它打開我的彈出視窗
function openClinetProfile() {
setClient(!client);
}
這是 jsx 我只想要它是如何完成的語法
{client ? <ClientProfile /> : null}
<table>
<tbody>
{filteredList(users, search).map((user) => (
<tr style={styles.tr}>
<button onClick= {openClinetProfile}>
// {user.id}
{user.firstname}
</button>
</tr>
</tbody>
</table>
ClientProfile 是一個彈出組件,我試圖將 {user.id} 傳遞給它
uj5u.com熱心網友回復:
這是你需要做的:
const [userId, setUserId] = useState();
const openClinetProfile = (id) => {
setUserId(id);
setClient(!client);
}
//other parts of your code
//...
//
{client ? <ClientProfile userId={userId} /> : null}
<table>
<tbody>
{filteredList(users, search).map((user) => (
<tr style={styles.tr}>
<button onClick= {() => openClinetProfile(user.id)}>
{user.firstname}
</button>
</tr>
</tbody>
</table>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/337033.html
標籤:反应
上一篇:無法將資料從反應發送到快遞服務器
