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.

Function in Props

See original GitHub issue

When i put some functions on the Component, the Whole function including __WEBPACK_IMPORTED_MODULE... shows on jsx addons.

even with @storybook/addon-actions, JSX preview has shown as

<Calendar
  onSelect={function action() {
    for (var _len = arguments.length, _args = Array(_len), _key = 0; _key < _len; _key++) {
      _args[_key] = arguments[_key];
    }

    var args = _args.map(_util.prepareArguments);
    var channel = _addons2.default.getChannel();
    var id = (0, _v2.default)();
    channel.emit(_.EVENT_ID, {
      id: id,
      data: { name: name, args: args }
    });
  }}
/>

This is not what I expected… but is this intended?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
stramelcommented, Jul 26, 2018

This is a quick util function I wrote.

import { action as _action } from '@storybook/addon-actions'

export const action = (...args) => {
  const tempAction = _action(...args)
  tempAction.toString = () => `action('${args[0]}')`
  return tempAction
}

to use it just import the util function instead of the library function.

import { action } from './utils'
9reactions
ndelangencommented, Jan 10, 2018

Hmm, I think we could improve this by adding a toString on the action returned function: https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Function/toString

Read more comments on GitHub >

github_iconTop Results From Across the Web

Components and Props - React
This function is a valid React component because it accepts a single “props” (which stands for properties) object argument with data and returns...
Read more >
How To Pass A Function As A Prop In React? - Tim Mousk
Create a function in the parent component that accepts a callback as an argument. · Pass the function to the child component as...
Read more >
Full React Tutorial #13 - Functions as Props - YouTube
Course Files:+ https://github.com/iamshaunjp/Complete-React-Tutorial ‍ ‍ JOIN THE GANG ...
Read more >
React tutorial for beginners #20 Pass Function as Props
In this react js tutorial for beginners series we learn how to pass function as a props in child component in react js....
Read more >
How to Use and Pass Functions as Props— React - Medium
This has been the basics of passing functions as props in React. I hope this has given some insight on how to start...
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