0
stateからの既存のデータ(redux-persistから提供される)を持つコンポーネントをレンダリングしようとしています。データはstate.login.userです(これはmapStateToPropsデータオブジェクトと呼ばれ、返すされている機能:state.login.userが、DataObjectが更新されていないと、そのせいでcomponentWillReceivePropsで呼び出されていないネイティブcomponentsetWillUpdateが反応しない
あなたは何イムが間違っているのに私を指すことができ
import React from 'react'
import { connect } from 'react-redux'
import { ScrollView, AppRegistry, Component, Text, Image, View, Button, Modal, TouchableOpacity } from 'react-native'
import { GiftedForm, GiftedFormManager } from 'react-native-gifted-form'
// Styles
import styles from './Styles/MyProfileScreenStyles'
class MyProfileScreen extends React.Component {
constructor (props, context) {
const dataObject = {
profile: {
last_name : undefined,
}
}
super(props, context)
this.state = {
form: {
lastName: dataObject.profile.last_name,
tos: false
}
}
}
handleValueChange (values) {
this.setState({form: values})
}
componentWillReceiveProps (newProps) {
console.tron.log("componend will receive")
console.tron.log(newProps)
if (newProps.dataObject) {
this.setState({
dataObject: newProps.dataObject
})
}
}
render() {
const {lastName, tos, gender} = this.state.form
console.log('render', this.state.form)
return (
<View style={styles.container}>
<GiftedForm
formName='signupForm'
openModal={(route) => { this.props.navigator.push(route) }}
onValueChange={this.handleValueChange.bind(this)}
>
<GiftedForm.TextInputWidget
name='lastName'
title='Last name'
placeholder='Last name'
clearButtonMode='while-editing'
value={lastName}
/>
<GiftedForm.HiddenWidget name='tos' value={tos}/>
</GiftedForm>
</View>
)
}
}
const mapStateToProps = (state) => {
if(state.login.user !== null){
console.tron.log("test map state to props")
return {
dataObject: state.login.user
}
}
return {}
}
export default connect(mapStateToProps)(MyProfileScreen)
。?
どのようにpropsをstate.login.userに設定しますか? – AleXzpm
あなたのコンストラクタで 'props.dataObject'を使うべきときに' dataObject'を定義します。 – Jwebbed
this.state put 'dataObject:props.dataObject'にあります。 –