Skip to content

Instantly share code, notes, and snippets.

View haldarmahesh's full-sized avatar

Mahesh Haldar haldarmahesh

View GitHub Profile
import React, { Component } from 'react'
import ThemeContext from './context/ThemeContext';
export default class Body extends Component {
render() {
return (
<ThemeContext.Consumer>
{
(theme) => (
<div className="body" style={{color: theme.fontColor, background: theme.bodybg}}>
import React, { Component } from 'react';
import Header from './Header.component';
import Body from './Body.component';
import ThemeContext from './context/ThemeContext';
import {themeConfig} from './context/ThemeContext';
class App extends Component {
constructor() {
super();
@haldarmahesh
haldarmahesh / react-context-create.js
Last active October 5, 2018 19:08
medium-react-context-demo
import React from 'react';
import lightLogo from './../assets/medium_light.png';
import darkLogo from './../assets/medium_dark.png';
export const themeConfig = {
light: {
headerBg: '#F7B30C',
fontColor: 'black',
bodybg: 'white',
logo: lightLogo
},
render() {
<div>
<PlayHeader>
<Status/>
<VolumeBar/>
<SeekBar/>
</PlayHeader>
</div>
}
componentDidMount() {
if (this.props.modules) {
this.props.modules.forEach(function (module) {
module(Highcharts);
});
}
// Set container which the chart should render to.
this.chart = new Highcharts[this.props.type || "Chart"](
this.props.container,
this.props.options
componentWillUnmount() {
this.chart.destroy();
this.resetLocalStorage();
this.clearSession();
}
componentWillReceiveProps(nextProps) {
if (this.props.status !== nextProps.status) {
this.setState({
status: nextProps.status
});
}
}
componentDidUpdate(prevProps, prevState) {
}
componentWillUpdate(nextProps, nextState) {
}
shouldComponentUpdate(nextProps, nextState) {
let shouldUpdate = this.props.status !== nextProps.status;
return shouldUpdate;
}