Use React's Context API to simplify the interface
See original GitHub issueWhat do you think about using the Context API for configuration and to share next-i18next
options? User’s _app.js
would transform to something like the following (changes annotated with comments):
import React from 'react'
import App, { Container } from 'next/app'
// import { appWithTranslation } from '../i18n' this line changes to...
import appWithTranslation from 'next-i18next'
// the user imports configuration from their file
import config from '../i18n'
class MyApp extends App {
render () {
const { Component, pageProps } = this.props
return (
<Container>
<Component {...pageProps} />
</Container>
)
}
}
// use config in appWithTranslation
export default appWithTranslation(MyApp, config)
Then references to things like:
import { Link } from '../i18n';
can be changed to something like:
import Link from 'next-i18next'
and we wouldn’t have to wrap our components into functions to store configuration. To me, the interface now feels more “package-like”. Thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
React Context — Simplified - JavaScript in Plain English
React Context is a powerful tool when using inside React applications. It simplifies retrieving the state or updating it without the need to ......
Read more >Use React's Context API to simplify the interface #105 - GitHub
Passing configuration into React components. For this, perhaps there are solutions better than the Context API (for example, a HoC may be better ......
Read more >Context - React
Context provides a way to share values like these between components without having to explicitly pass a prop through every level of the...
Read more >How to Work with the React Context API - Toptal
This new API solves one major problem–prop drilling. Even if you're not familiar with the term, if you've worked on a React. js...
Read more >React Context API: A deep dive with examples - LogRocket Blog
In this tutorial, we'll explore how we can use React Context to avoid prop drilling.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@capellini Yes, I agree with that. I’ve created a 1.0 milestone for us to track related work.
On the one hand, I am very excited for the production release.
On the other hand, as this is a large change to the API, this would be a major breaking change, which may be a bit more disruptive to our users post-production release. Major breaking changes happen, so it’s not a show-stopper, but if we could sort it out before then, I think that would be ideal.
I don’t think it would take much effort to create a quick prototype to give you and @kachkaev an idea of what things would look like. If, after seeing it, we decide to not go forward with it, no big deal.