i18next / react-i18next

Internationalization for react done right. Using the i18next i18n ecosystem.
https://react.i18next.com
MIT License
9.32k stars 1.03k forks source link

Simplifies hasValidReactChildren #1764

Closed VIKTORVAV99 closed 4 months ago

VIKTORVAV99 commented 4 months ago

Simplifies hasValidReactChildren a bit by utilizing Array.isArray, implicit returns and the fact that .every() can take a function without arguments as it's own argument.

This no longer returns false when it's not an array but rather implicitly returns undefined which don't affect current functionality as the code it's used in just checks for truthy values.

Checklist

coveralls commented 4 months ago

Coverage Status

coverage: 97.143% (-0.003%) from 97.146% when pulling f97b826f9c0744ddb463fdbe94447f10fdc145d3 on VIKTORVAV99:simplify_hasValidReactChildren into a904e07d0708395068c3b55f70a6c5ce13f9e315 on i18next:master.

VIKTORVAV99 commented 4 months ago

@adrai how do you feel about making some changes that might potentially be breaking changes?

I'm thinking about optional chaining and removing the code here: https://github.com/i18next/react-i18next/blob/92bc14704e447ac38973b804e852c7ccd6c1c15a/src/utils.js#L56-L96

Both of these changes should be supported by the current build config as far as I can tell. Browserslist is configured to only target the default browsers and the code in question is never used if the peer dependency version of i18next is followed.

adrai commented 4 months ago

same topic like https://github.com/i18next/i18next/pull/2184

VIKTORVAV99 commented 4 months ago

What about removing the old code then? That has nothing to do with system compatibility and should be fine as long as the peer versions are followed.

adrai commented 4 months ago

yes, I think 3 years later, we can remove that old code for a future major version (also conditional chaining)... as soon as you "finished" to create other PRs... (non-breaking) I will create a NON-major version, and afterwards we can go for a new major version, ok?

VIKTORVAV99 commented 4 months ago

Sounds good!

I'll go through the code a final time and see if I find any other small opportunities to optimise the current code without breaking changes.