0
I started studying React Native in version 0.55.4, and it seems to have changed a few things in the most current version (0.59.8), now I’m having difficulty passing/assigning values in the this.props.modificaNome
, follows an example below of how I do in a TextInput
and the error it presents:
Dependencies used:
"dependencies": {
"firebase": "^5.7.3",
"react": "16.8.3",
"react-native": "0.59.8",
"react-native-router-flux": "^4.0.6",
"react-redux": "^7.0.3",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
I don’t know if this change was in React Native or Redux. But it is presenting the following error:
Example of my code:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import {
View,
StyleSheet,
StatusBar,
Text,
TouchableHighlight,
TextInput
} from 'react-native';
import {
modificaNome
} from '../reducers/AutenticacaoReducers';
class Confirmar extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<View style={{ flex: 1, backgroundColor: '#FFF' }}>
<StatusBar backgroundColor="#104E8B" barStyle="light-content" />
<View>
<TextInput
placeholder=" Digite o seu nome... "
style={{ fontSize: 15, height: 50 }}
selectionColor="#696969"
underlineColorAndroid="#FFFFFF"
returnKeyType="go"
multiline={false}
numberOfLines={1}
spellCheck={false}
maxLength={15}
autoCorrect={false}
value={this.props.nome}
onChangeText={texto => this.props.modificaNome(texto)}
/>
<TouchableHighlight
style={Estilos.buttom}
underlayColor='#CDC9C9'
accessibilityLabel="Clique aqui para ler o meu convite."
onPress={() => {}}>
<Text style={{ color: '#FFF', fontSize: 18, fontWeight: 'bold' }}>OK</Text>
</TouchableHighlight>
</View>
</View>
)
}
}
const Estilos = StyleSheet.create({
buttom: {
alignItems: 'center',
justifyContent: 'center',
borderColor: '#3A5FCD',
backgroundColor: '#04B45F',
borderWidth: 0.5,
borderRadius: 100,
width: 280,
height: 40
},
})
const mapStateProps = state => ({
nome: state.AutenticacaoReducers.nome,
});
export default connect(mapStateProps, {
modificaNome,
})(Confirmar);
My Authenticated One and Two:
import {
MODIFICA_NOME,
} from './../actions/Types';
const INITIAL_STATE = {
nome: '',
}
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case MODIFICA_NOME:
return { ...state, nome: action.payload }
default:
return state;
}
}
My Authenticcaoactions:
import {
MODIFICA_NOME,
} from './Types';
export const modificaNome = (texto) => {
return {
type: MODIFICA_NOME,
payload: texto
}
}
Thank you so much for your help, friend, I’ve been trying to solve this problem for days... I made these changes that you guided me, but the error continues. And I do not understand, it is not necessary to make a change in Autenticacaoactions and Autenticacaoreducers?
– Lucas Guimarães
The error now is: Authentification.modifiName is not a Function
– Lucas Guimarães
This answer is incorrect. You are doing it the right way, try to update your Redux and see what happens
– Murilo Medeiros
Try changing onPress={() => {}} to onPress={() => false} may not be the solution, but this is good practice
– Murilo Medeiros