我希望能够将当前用户从我的Comment
组件传递到我的CommentList
组件
class Comment extends Component {
render() {
return(
<View>
<Header
rounded
style={{
backgroundColor: '#ffffff',
position: 'relative',
}}
>
<View style={{flexDirection: 'row', flexWrap: 'wrap', right: '43%', top: '50%'}}>
<Icon name='chevron-left' size={10} color='#006FFF' style={{top: '6%'}}/>
<NativeText
onPress={() => this.props.history.push('/')}
style ={{color: '#006FFF', fontSize: 12, fontFamily: 'Montserrat-Regular'}}
>
Back
</NativeText>
</View>
</Header>
<View
style={{paddingLeft: '2%', paddingTop: '2%'}}
>
<CommentList
options={this.props.location.state.comments}
currentUser={this.props.location.state.currentUser}
/>
</View>
</View>
)
}
}
export default withRouter(Comment)
const CommentList = (options, currentUser) => {
const [modalVisible, setModalVisible] = useState(false)
const [parentId, changeParentId] = useState('')
const [commentInput, changeComment] = useState('')
return (
<View>{console.log(currentUser)}
{options.options.map(option => (
<View>
<NativeText
style={{fontSize: 12, fontFamily: 'Montserrat-Regular'}}
>
{option.content}
</NativeText>
<Icon
name='reply'
size={12}
onPress={() => {
setModalVisible(true)
changeParentId(option._id)
}}
/>
{
<View
style={{left: '10%'}}
>
<CommentList
options={option.reply}
/>
</View>
}
</View>
))}
</View>
)
}
当我尝试通过
currentUser
传递它时,它返回一个空对象。 options
确实显示在CommentList
中。 最佳答案
您缺少CommentList的对象解构语法。应该如下:
const CommentList = ({ options, currentUser }) => {
// component content
}
关于javascript - 无法让子 Hook 接收状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57135459/