molindo / eslint-config-molindo

ESLint config that implements the Molindo styleguide and helps to catch errors.
MIT License
1 stars 2 forks source link

Evaluate `react/no-unstable-nested-components` #77

Closed amannn closed 10 months ago

amannn commented 2 years ago

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unstable-nested-components.md

I was a bit unsure which of these patterns is preferable for a longer time:

function LinkButton({href, ...rest}) {
  const Component = useMemo(() =>
    function Link(props) {
      return <a href={href} {...props} />
    },
    [href]
  );

  return <Button as={Component} {...rest} />
}
function LinkButton({href, ...rest}) {
  return <Button as="a" href={href} {...rest} />
}

… the second one has the advantage that the component remains mounted for the lifetime of the component. I was concerned however about handling an unknown prop like href within Button.

After discovering react-polymorphic-types I'm now largely in favour of the second approach. I'm not sure yet if it's worth linting for, but we could consider it.

I'd set allowAsProps to true in any case to not be too restrictive.