-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
Description
Given the following code snippet from the readme:
const Composed = adopt({
cart: <Cart />,
user: <User />,
shippingRates: ({ user, cart, render }) => (
<ShippingRate zipcode={user.zipcode} items={cart.items}>
{render}
</ShippingRate>
)
})How do you know in which order to apply the render prop components? Does this rely on the order of keys returned from Object.keys(mapper) call here?
As far as I know, object property order is not guaranteed. Asking because I'd love to use this library, but wondering if this could lead to some nasty (maybe cross browser) bugs.
Example of what could go wrong
const First = ({ children }: FirstProps) => children("foo");
const Second = ({ first, children }: SecondProps) => children(`${first}bar`);
const Display = ({ first, second }: DisplayProps) => (
<div>
First: {first}
<br />
Second: {second}
</div>
);
const Composed = adopt({
first: <First />,
second: ({ first, render }) => <Second first={first}>{render}</Second>
});
const ComposedInverse = adopt({
second: ({ first, render }) => <Second first={first}>{render}</Second>
first: <First />,
});
const App = () => (
<div style={styles}>
<h3>Correct order</h3>
<Composed>
{({ first, second }) => <Display first={first} second={second} />}
</Composed>
<h3>Inversed</h3>
<ComposedInverse>
{({ first, second }) => <Display first={first} second={second} />}
</ComposedInverse>
</div>
);Result
lucasconstantino, darkowic, nderscore, AndyLyons and romankrru
