question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use React's Context API to simplify the interface

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
isaachinmancommented, Jan 20, 2019

@capellini Yes, I agree with that. I’ve created a 1.0 milestone for us to track related work.

1reaction
capellinicommented, Jan 18, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found