question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow providing callback prop to execute the command

See original GitHub issue

Is your feature request related to a problem? Please describe. My problem is the command property must be a function. Because of that, I must use this in it for the object to be testable.

Describe the solution you’d like I suggest introducing a new prop executeCommand: (command: Command) => void which will take the command object and execute it. That way the command object can contain only data and no this need to be used.

Additional context An example would be: Without executeCommand:

function go() {
    history.go(this.link);
}

const props = {
  options: [
    {
      name: "Go to example",
      link: "http://example.com",
      command: go
    },
  ],
};

With executeCommand:

const props = {
  options: [
    {
      name: "Go to example",
      link: "http://example.com",
    },
  ],
  executeCommand: (command) => {
    history.go(command.link)
  }
};

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asabayluscommented, Oct 8, 2020

@iddan I’ve got a few other enhancements to get to first but I’m open to a pull request

1reaction
asabayluscommented, Oct 8, 2020

Yes, you’d be using onSelect much like the browser native drop down list box and matching on the returned object so that your function could be executed.

For context, I’ve periodically considered eliminating the inclusion of functions passed to the commands prop. It’s really not required and breaks with native browser control conventions. However, I wanted a batteries included component the was easy to use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass a Callback as Props - React - Free Code Camp - YouTube
In this React tutorial we pass a callback as props. This video constitutes one part of many where I cover the FreeCodeCamp ...
Read more >
FreeCodeCamp/pass-a-callback-as-props.english.md at master
This is how you allow child components to interact with their parent components. You pass methods to a child just like a regular...
Read more >
React: how to pass arguments to the callback - Stack Overflow
What you can do is create a partially applied or higher order function to enclose the item.id and pass it along. So let's...
Read more >
Create Callbacks for Graphics Objects - MATLAB & Simulink
A callback is a command that executes in response to some predefined user action, such as clicking on a graphics object or closing...
Read more >
Dealing with callbacks as props in React - DEV Community ‍ ‍
When we declare callback as onClick={this.fetchUsers} every render call will pass the same onClick reference to the button . At the time, when ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found