Skip to content Skip to sidebar Skip to footer

Same Function In Vue And React But Doesnt Work In React

Im doing the same login function in React/Vue. It works fine on VueJS but when i use in ReactJS it doesnt work. Vue working fine: async EnvioLogin() { try { const response =

Solution 1:

In js, this behaves differently in ordinary function and arrow function. And there is also difference between strict mode and non-strict mode.

Specially, arrow function don't bind to the caller's context. If your function/the lib you use actually depends on this behaviour, it would create some very obscure bug.

Your 2 functions are defined differently. The first one is ordinary function and the second one is arrow function. and they also reference this.

You could check on the usage of this first. But it will be hard to understand the problem without more context/reproducible code.

SEE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

Post a Comment for "Same Function In Vue And React But Doesnt Work In React"