Downshift: Can't compose Downshift with other 'render prop' components because of validateGetRootPropsCalledCorrectly

Created on 27 Jul 2018  路  5Comments  路  Source: downshift-js/downshift

  • downshift version: 2.0.19
  • node version:
  • npm (or yarn) version:

Reproduction repository:
https://codesandbox.io/s/jjk32o429y

Problem description:
(I've seen #235 and aware of the suppressRefError workaround but it doesn't work for this use case, as demonstrated.)

I'm trying to 'compose'/'chain' Downshift with another 'render prop' component. (My reproduction example is deliberately trivial but composability is, I think, a really useful property of the 'render prop' pattern.)

I've got the example working in this fork:
https://codesandbox.io/s/oo096p975y

I have had to hack the Downshift code to make it work:

  • In render(): this.getRootProps.called = true. (I do call it.)
  • In validateGetRootPropsCalledCorrectly(): change a throw new Error to console.warn
  • In input_handleBlur() add a console.log(this._rootNode) just to demonstrate it has been set correctly

Suggested solution:
Perhaps adding a suppressRefError prop to the Downshift component itself to allow this use case?

And thanks so much for Downshift!

enhancement good first issue help wanted

All 5 comments

What if you did this: https://codesandbox.io/s/93kqpy8lvp

Yes, that works, but it entangles the presentational root div inside the logic components (Downshift and Foo). It prevents us extracting a reusable pure logic component DownshiftWithFoo:

const DownshiftWithFoo = () => <Downshift>{() => <Foo/>}</Downshift>

Interesting... Ok, I'd be fine with an (undocumented) prop for this use case. PRs accepted. Thanks @jf248!

Thanks, I'll send a PR

I8

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuripramos picture yuripramos  路  4Comments

klapouchy picture klapouchy  路  4Comments

the-simian picture the-simian  路  4Comments

oliverjam picture oliverjam  路  3Comments

emp823 picture emp823  路  4Comments