Add to global state in React Native without Redux

I think I solved it. I add my solution for if anyone finds it useful in the future. Solved it by eliminating the class while passing parameters to routes

class HomeScreen extends React.Component{
  constructor(){
    super();
    this.state={
      sueldo:'',
    }
  }

I replaced every this.state and simply passed the parameter along with the navigation:

function HomeScreen({navigation}){
  const [text, setText] = useState('');
return (
<View>
     <TextInput style={styles.textInput}
      placeholder=""
      onChangeText={text => setText(text)}
      defaultValue={text}/>
    <View>
    <TouchableOpacity style={styles.saveButton}
    onPress={()=> navigation.navigate('Screen2', {
      bruto: text})}>
      <Text style={styles.saveButtonText}>Next</Text>
    </TouchableOpacity>
</View>);
}

This was the main code I followed and edited to get to the solution

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top