bluewings / pug-as-jsx-loader

MIT License
188 stars 15 forks source link

How to pass a function and return ReactNode? #36

Open billypon opened 5 years ago

billypon commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

@bluewings

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

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

billypon commented 5 years ago

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