babel-plugin-jsx-adopt icon indicating copy to clipboard operation
babel-plugin-jsx-adopt copied to clipboard

Multiple arguments?

Open drcmda opened this issue 6 years ago • 3 comments

Is this possible? I couldn't make it work

<Grid >
    {(item, opened, toggle) => {

a possible solution could be

const [item, opened, toggle] = adopt(<Grid />)

drcmda avatar Aug 29 '18 18:08 drcmda

That's not quite possible, because it would be ambigous with:

<Grid >
    {([item, opened, toggle]) => {

And I can't statically know which one do you want. Supporting the given by me example allows for a good interoperability with existing, built in mechanism of context (which always provide a single argument to ur render props, which might be an array)

Andarist avatar Aug 29 '18 21:08 Andarist

Makes sense. adoptObj/adoptArray would work, but it's ugly. I'll carry on trying to avoid ...args.

drcmda avatar Aug 30 '18 07:08 drcmda

adaptObj actually would not be needed because this:

const { item, opened, toggle } = adopt(<Grid />)

is very much supported - it's a single destructured argument.

I would generally advise of avoiding ...args in render props and stick to a single argument to keep "compatibility" with what kind of APIs React provides.

Andarist avatar Aug 30 '18 09:08 Andarist