Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass a function and return ReactNode? #36

Open
billypon opened this issue Sep 15, 2019 · 3 comments
Open

How to pass a function and return ReactNode? #36

billypon opened this issue Sep 15, 2019 · 3 comments

Comments

@billypon
Copy link
Contributor

How to pass a function and return ReactNode?

Like this example, how to transform it to pug file?

render() {
  return (
    <MyComponent renderFunction={ data => <div>{ data }</div> } />
  );
}
@bluewings
Copy link
Owner

@billypon
You can receive them from a parent function or describe them in pure jsx syntax.

div
  // from parent
  MyComponent(renderFunction='{renderFunction}')
  // inline function with jsx
  MyComponent(renderFunction='{data => <div>{data}</div>}')
import React from 'react';

export default function (params = {}) {
  const { renderFunction, MyComponent } = params;
  return (
    <div>
      { /* from parent */ }
      <MyComponent renderFunction={renderFunction} />
      { /* inline function with jsx */ }
      <MyComponent renderFunction={data => <div>{data}</div>} />
    </div>
  );
}

@billypon
Copy link
Contributor Author

@bluewings

MyComponent(renderFunction='{data => <div>{data}</div>}')

But this code <div>{data}</div> isn't pug syntax, just html syntax.

@billypon
Copy link
Contributor Author

The renderFunction from parent can work, but I want this function place in pug file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants