React Native - how to trim a string
The problem is in your setEmail
call and the ES6 syntax that you are using. When you do:
email => this.setEmail({email})
The transpiler transforms it into the following:
email => this.setEmail({email: email})
Which of course is an object.
Then, inside the function, you are trying to apply the trim
function to an object, which of course results in failure. Try this instead:
email => this.setEmail(email)
You can read more on the ES6 syntax for object literals here.
In case the string you want to trim is a state and you want to trim the spaces, but not to render the whole page, then you can do it directly as following:
this.state.text = this.state.text.trim()