React Native - how to crop a string

I want to remove spaces from the beginning and end of a line. For example, given the line “Test”, I would like to get “Test”. I tried JavaScript methods as well as some npm libraries, but they don't seem to work with React Native? Any thoughts?

enter image description here

+4
source share
2 answers

The problem is the call setEmailand syntax of ES6 that you are using. When you do:

email => this.setEmail({email})

The transporter converts it to the following:

email => this.setEmail({email: email})

This, of course, is an object.

Then inside the function, you try to apply the function trimto the object, which of course leads to an error. Try instead:

email => this.setEmail(email)

ES6 .

+4

trim . , , nbsp .., :

"\u2007 TEST \t\n".replace(/^\s+|\s+$/g, ""); // "TEST"
+1

Source: https://habr.com/ru/post/1663327/


All Articles