Skip to content

Instantly share code, notes, and snippets.

@jkantr
Forked from davidrosenlund/gist:21489ba2511170090ba3bc5e176ed044
Last active November 25, 2019 18:37
Show Gist options
  • Save jkantr/c2809697cb098305edf6ad03bf91788b to your computer and use it in GitHub Desktop.
Save jkantr/c2809697cb098305edf6ad03bf91788b to your computer and use it in GitHub Desktop.
import BonusContext from './bonus-context';
class App extends Component {
static contextType = BonusContext;
render() {
return(
<li className={ this.context ? 'current' : '' }>
<NavLink
exact
to="/bonuses"
data-hover="Alla Bonusar">
Alla Bonusar
</NavLink>
</li>
);
}
}
Child component Bonuses.js
#########################
const BonusContext = React.createContext(true);
class Bonuses extends Component {
...
export const BonusContext = React.createContext({
bonus: false
toggleBonus: () => this.bonus = !this.bonus
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment