How to call a returned function with params? Javascript

So Im doing an editor in react and im adding some extra tools so I need to change the toolbar depending on the selected item.

Before I only had one toolbar with this method:

bottomToolbar.updateToolbar( nodeattrs.align,
                                                 nodeattrs.fontFamily,
                                                 nodeattrs.fontSize,
                                                 nodeattrs.fill,
                                                 nodeattrs.stroke,
                                                 nodeattrs.strokeWidth )

But the new toolbar has different parameters, it only takes 4 arguments.

No my new toolbar renders the correct toolbar depending on its state, I want the class method updateToolbar to change depending on what toolbar is rendering so I can skip the if evaluation checking the selected toolbar, I dont want to check it everytime I call updateToolbar.

switch(this.state.selectedToolbar){
        case "SelectorAndText":
          return <TextBottomToolbar 
                    ref={this.bottomToolbarRef}

                    fontSizeUpdater    = {this.fontSizeUpdater}
                    fontColorUpdater   = {this.fontColorUpdater}
                    strokeColorUpdater = {this.strokeColorUpdater}
                    strokeSizeUpdater  = {this.strokeSizeUpdater}
                    fontFamilyUpdater  = {this.fontFamilyUpdater}
                    alignmentUpdater   = {this.alignmentUpdater}
                 />
        break
        case "FreeLine":
            return <LineBottomToolbar 
                    ref={this.bottomToolbarRef}

                    strokeColorUpdater={this.updateStrokeColor.bind(this)}
                    strokeSizeUpdater={this.updateStrokeSize.bind(this)}
                    shadowColorUpdater={this.updateShadowColor.bind(this)}
                    shadowSizeUpdater={this.updateShadowSize.bind(this)}
                   />
        break

As you can see I have a ref to the correspondient toolbar so I want to call the method in pseudo code would be something like this:

updateToolbar(){
    //return selectedToolbarRef.current.updateToolbar
}

So when i call outside bottomtoolbar.updateToolbar(bla, bla, bla) or .updateToolbar(bla, bla) It uses the returned function



Read more here: https://stackoverflow.com/questions/67944426/how-to-call-a-returned-function-with-params-javascript

Content Attribution

This content was originally published by ByteVictor at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: