[英]How to display input box value from addImg.js (child component) to app.js (parent component) in react
[英]React JS How to display component onclick, but not in App.js
React JS如何顯示組件onclick,但不在App.js中
這將在 App.js 中
var [clicks, setClicks] = useState(false)
return(<>
{clicks && <Component />} //this will display if clicks are true
<button onClick={function(){setClicks(true)}}>click me<button/>
</>)
但是如果我在另一個文件中沒有 UseState 而不是 App.js 怎么辦
通過使用 Redux,您可以在不同頁面上的多個組件上使用相同的 state。
有兩種方法可以做到 1.您需要將 state 提升到 App.js。 將 state 作為道具傳遞給您要使用的組件。 2.您需要使用state管理工具,如Redux。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.