Open calebjacob opened 8 months ago
This is working for trusted Components since the introduction of the Babel plugin. Sandboxed Components still have some difficulty, since <Component />
is a stub and not an actual React Component. It doesn't look like much work to get it in parity though.
import Child from './Child';
import Parent from './Parent';
import s from './styles.module.css';
function Root() {
return (
<div className={s.wrapper}>
<Parent bwe={{trust:{mode:'trusted'}}}>
<Child />
<p>Hello!</p>
</Parent>
</div>
);
}
export default Root as BWEComponent;
candidate to kick out to P1
It's a very common React pattern to pass
children
into a component. You'd set up your component to take in achildren: ReactNode
prop like so:You would then expect to use
<Parent>
like so:However, this exact syntax isn't currently supported due to all props needing to be passed through an explicit
props
object. This will be resolved here: https://github.com/near/bos-web-engine/issues/261Until that issue is resolved, you can use this syntax - and everything will work if we only pass in native DOM components (eg:
p
,div
, etc):However, it's very common that we'd need to pass in our own component as a child. Let's set up a new component:
Then we update our root component to pass
<Child>
to<Parent>
like so:The engine throws the following error saying
Child
is an unrecognized component:This is a very common use case when building out more robust React applications. For a more concrete example, imagine you needed to build a
<Theme>
component that can be used to wrap multiple pages/components and provide CSS variables to all of its children. In an ideal world, the BOS engine would support the following: