Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does func.apply(this, arguments) do in this code for _.once()?

Tags:

javascript

The following function underbar function was rewritten by peer of mine like so:

    var once = function(func) {
        var alreadyCalled = false;
        var result;

        return function() {
          if (!alreadyCalled) {
            result = func.apply(this, arguments);
            alreadyCalled = true;
          }
        return result
        };
      };

Here's how I interpret it. It's a function that takes another function and returns yet another function. If alreadyCalled is false then set result = func.apply(this,arguments)

Can someone please help me understand in a simple way what func.apply(this,arguments) is doing in the context of this function. I can't seem to figure it out!

like image 927
theamateurdataanalyst Avatar asked Feb 11 '23 22:02

theamateurdataanalyst


1 Answers

remove async await from

React.useEffect(async () => { await something},[]);

then it works just remove async await

React.useEffect(() => { something},[]);

I know your code is different but i got the same issue i remove async from all of the project which was used within useEffect and i dint saw the error again anymore

like image 189
Rahul Shakya Avatar answered Feb 13 '23 16:02

Rahul Shakya