我對本機反應(博覽會)中的模態有一個奇怪的問題。我的模態看起來像這樣:const useNewCommentModal = () => { const [showModal, setShowModal] = useState(false); const [comment, setComment] = useState(''); const toggle = () => { setShowModal(!showModal); }; const NewCommentModal = () => ( <Modal visible={showModal} animationType="slide"> <View style={[t.pX4]}> <TextInput style={[t.bgWhite, t.p2, t.rounded, t.textLg]} placeholder={'Post jouw reactie...'} onChangeText={text => setComment(text)} value={comment} /> </View> </Modal> ); return [toggle, NewCommentModal];};export default useNewCommentModal;當我鍵入時,模態不斷重新打開。當我刪除它時:onChangeText={text => setComment(text)}問題消失了,但顯然狀態不再更新。為什么模型不斷重新打開?- 編輯 - const [toggleModal, NewCommentModal] = useNewCommentModal( 'user', route.params.user.id );<NewCommentModal />
React 本機 setState 鉤子重新打開模式
呼如林
2022-05-22 10:31:24