Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix withTranslation eating up forwardedRef prop #992

Merged
merged 1 commit into from Nov 13, 2019

Conversation

@emroussel
Copy link
Contributor

emroussel commented Nov 12, 2019

When wrapping components with only the withTranslation HOC, this code works well:

export const Input =  withTranslation('translation', { withRef: true })(Input),

But when using multiple ones, withTranslation was not propagating forwardedRef to its children, making code like this break (it also used to work in previous versions):

const InputWithRef = compose(
    withTranslation(),
    withSomeOtherHOC(),
    withProps(({ forwardedRef }) => ({ ref: forwardedRef }))
)(Input);

export const Input = React.forwardRef(
    (props, ref) => <InputWithRef {...props} forwardedRef={ref} />
);

Fixes #990

@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 12, 2019

Coverage Status

Coverage remained the same at 95.444% when pulling f44cdcf on emroussel:fix-forwardedRef-prop into 9aa7c3c on i18next:master.

@jamuhl jamuhl merged commit 99c927d into i18next:master Nov 13, 2019
4 checks passed
4 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
codeclimate All good!
Details
coverage/coveralls Coverage remained the same at 95.444%
Details
workflow Workflow: workflow
Details
@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Nov 13, 2019

published in react-i18next@11.2.0

@felixmosh

This comment has been minimized.

Copy link

felixmosh commented Nov 17, 2019

Hi, thank you for this PR.

I've updated to latest, and looks like now there is a prop (forwardedRef) that is passed to Link component (of Next), and that throws warning:

Warning: Failed prop type: Link: unknown props found: forwardedRef
    in Link
    in Link
    in withI18nextTranslation(Link)
    in withnextI18NextInternals(withI18nextTranslation(Link)) (at TextLink.tsx:14)
    in TextLink (at Logo.tsx:8)
@adrai

This comment has been minimized.

Copy link
Contributor

adrai commented Nov 17, 2019

Perhaps only pass when options.withRef?

@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Nov 17, 2019

best will be only adding it if it's not undefined

@emroussel

This comment has been minimized.

Copy link
Contributor Author

emroussel commented Nov 18, 2019

@jamuhl @adrai @felixmosh checkout #999, should fix the issue

@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Nov 19, 2019

fix was published in react-i18next@11.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.