I want to delete the whitespaces from the beginning and the end of a string. For example, given a string " Test ", I would like to receive "Test". I have tried JavaScript's methods and also some npm libraries, but they don't seem to work with React Native? Any thoughts?
React Native allows you to automatically truncate text that will not fit within its <View> container. In most cases this is enough for the device to truncate the text, automatically adding ellipsis to the end of the string (…) after however many lines of text you have specified (In this case, we only want 1 line).
You can also split() the string to array and then find the indexOf() the work, then join() using > to get the final result.
To remove the empty spaces from the string, use the replace() method in JavaScript. This method searches a string for a specified value and returns a new string replacing those values. It's commonly used to search a string for a regular expression and replace that expression with the desired substring.
The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With