udacity / fluent-react-utils

Archiving for now. May reference for future fluent use, but this package is not currently in use.
Other
6 stars 3 forks source link

makeLocalizedElement assumes stateless component is desired #13

Open danehammer opened 5 years ago

danehammer commented 5 years ago

I'm not sure how we could avoid this, and I've already patched my code to put the state a layer higher than the component definition, but thought I would share.

I have a customized TextInput that saves off a ref of the input on the instance. Renders something like:

<input
  ref='input'
  label='a string i need translated'
  ... />

And when that custom component is used with makeLocalizedElement:

const LocTextInput = makeLocalizedElement(TextInput, {label: true})

// ...

<LocTextInput
  ref='username'
  label='Username'/>

I get warned by React that I can't have a ref on the stateless functional component (the Loc returned by makeLocalizedElement)

Could we add something to makeLocalizedElement, maybe a flag, that it would branch on and instead create a stateful component?