我在制作组件数组时遇到了麻烦,所以我做了一些简单的事情:我有一个 TextInput 标签,每次我写一些东西时,它都会将一个组件推送到一个数组,但没有调用 Photo 组件,我知道这是因为有一个 console.log 在里面,什么也没有打印。 Photo comp 可以很好地导出和导入
function Research() {
var list = []
function searching(str) {
list.push(<Photo></Photo>)
console.log(list) // I DO have Photo components incrementing in the list meanwhile the Photo component itself is not called
}
return (
<TextInput type="text"
placeholder="Rechercher..."
onChange={(e) => searching(e.target.value)}>
</TextInput>
)
}
//照片组件
function Photo(props) {
console.log("Hello there") // nothing is printed
return (
<Text>Nothing<Text/>
)
答案 0 :(得分:0)
您没有在 Research 组件中渲染照片组件。试试这个:
return (
<>
<TextInput type="text"
placeholder="Rechercher..."
onChange={(e) => searching(e.target.value)}>
</TextInput>
{list}
</>
)