リアクションネイティブの初心者はここにあります。リアクションネイティブナビゲータでの小道具/状態の受け渡し
私は、本質的に単なる複数ページの連絡フォームである簡単なReact Nativeアプリを構築しようとしています。
私はここで私のコンポーネントに小道具を割り当てようとするたびに、私は私がナビゲーター(navigatorRenderScene機能)を介してそれらをレンダリングしていたときに私の子コンポーネントに小道具/状態を渡すための最良の方法
を考え出すのトラブルを抱えています文字列を渡すことはできますが、関数やオブジェクトは渡すことはできません。たとえば、まずコンポーネントで、文字列と関数を渡そうとしています。ページがレンダリングされると、文字列だけがその値を保持します。
私はこれを完全に間違った方法でやっていますか? FluxやReduxのような状態管理システムを調べる必要がありますか?たぶんreduxルータパッケージ? (まだ触れていないので正直である)
ルーティングはすごくうまくいっています。私は理解できない小道具です。
は、ここで私はそれがスコープを持つだ問題を考える
import React, { Component } from 'react';
import {
AppRegistry,
Navigator,
StyleSheet,
Text,
View,
TouchableHighlight
} from 'react-native';
import { Container, Header, Title, Content, List, ListItem, InputGroup, Input, Button, Icon, Picker } from 'native-base'
// too much stuff being imported, will clean this up later
class First extends Component {
constructor(props) {
super(props)
this.onButtonPress = this.onButtonPress.bind(this)
}
onButtonPress() {
this.setState({
text: 'changed state from first component'
})
console.log(this.state)
this.props.navigator.push({
id: 'Second'
})
}
render() {
return(
<Container>
{console.log('rendering first')}
<Content>
<List>
<ListItem>
<InputGroup>
<Input
placeholder='Name'
/>
</InputGroup>
</ListItem>
</List>
<TouchableHighlight onPress={this.onButtonPress}>
<Text>Go to Page 2</Text>
</TouchableHighlight>
</Content>
</Container>
)
}
}
export default First
arrow関数のメソッドが機能しました!それは間違いなく問題でした。 – n8e
助けてくれてありがとう、この1つはナットを運転していた。 – n8e