0

I have the following component in which I am trying to set the onSubmitEditing function of a TextInput element to a custom function called func. I would like it to take the content of the TextInput box as input to the function. How can this be done? Below is my failed attempt at doing so:

export default class Component4 extends Component {
    func(input){
        // will add stuff here later
    }

    render(){
        return (
            <View style={{padding: 30}}>
                <TextInput placeholder="default" onSubmitEditing=this.func/>
            </View>
        );
    }
}

PS:

Thanks to everyone so far for the help, I've managed to get it working partly, here is my code now:

export default class Component4 extends Component {
    constructor(props) {
        super(props);
        this.state = {thing: 'asdf'};
    }

    func(input){
        this.state.thing = input;
        // I will eventually do more complicated stuff here
    }

    render(){
        return (
            <View style={{padding: 30}}>
                <TextInput placeholder="default" onSubmitEditing={this.func}/>
                <Text>{this.state.thing}</Text>
            </View>
        );
    }
}

this gives an error, I am trying to make it so that state.thing gets set to the input. thanks

2 Answers 2

1

Option 1: <View style={{padding: 30}}> <TextInput placeholder="default" onSubmitEditing={this.func}/> </View>

Option 2: <View style={{padding: 30}}> <TextInput placeholder="default" onSubmitEditing {(e)=>this.func(e.target.value)}/> </View>

Sign up to request clarification or add additional context in comments.

Comments

0
state={
         text:''
}
Func(e){
        text:e.target.value
 }
 onSubmitChange={this.func}

Don't forget to bind the func function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.