機能コンポーネント内でユーザー入力を取得したい(私はredux
アーキテクチャを使用しています)。しかし、私がconsole.log()
参照された項目を参照すると、実際のオブジェクトではなくコンストラクタが得られます。TextInputは参照によって値を取得します。
状態を操作せずにユーザー入力を取得するにはどうすればよいですか?
<Modal visible={visibleModal === 'addRoom'} onRequestClose={() => null}>
<TextInput ref={el => {roomName = el}} style={styles.input} />
<Button onPress={() => store.dispatch(hideModal())}>Cancel</Button>
<Button onPress={() => {
store.dispatch(addRoom({name: roomName.value}))
return store.dispatch(hideModal())
}}>OK</Button>
</Modal>
ドキュメントのTextInput ref = {(c)=> this._input = c} 'に基づいて、その値を返す必要があります。おそらくこれを使用します。それをコンストラクタで見ることができます。 – ajmajmajma