3 ms·
I genuinely don't understand this comment or the reason for writing it as a hook or a separate component in the article Why wouldn't you just write it as a fun
by aniforprez 5y ago
I genuinely don't understand this comment or the reason for writing it as a hook or a separate component in the article
Why wouldn't you just write it as a function with data and context being passed through as arguments? Isn't it much simpler to write a pure function and test that function than render a component and test it? If you simply write a function that accepts the locale, the string and context, does the translator magic and returns the translated text, would you not then just need to write a unit test simply to make sure you're getting the expected output? Why the abstraction into hooks and then further into a separate component that you then have to render?
- eliseumds 5y agoIt doesn't matter what your code is doing inside that component, you can still make it easily testable by having the core translation pipeline as pure functions. See https://news.ycombinator.com/item?id=27031847 https://news.ycombinator.com/item?id=27031847 for more reasons.