Skip to content

Instantly share code, notes, and snippets.

componentWillUnmount() {
this.chart.destroy();
this.resetLocalStorage();
this.clearSession();
}
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
render() {
<div>
<PlayHeader>
<Status/>
<VolumeBar/>
<SeekBar/>
</PlayHeader>
</div>
}
@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
},
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();
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}}>
@haldarmahesh
haldarmahesh / react-constructor-16.4.jsx
Created October 17, 2018 07:59
react-constructor-16.4.jsx
class ContraMusicPlayer extends React.Component
constructor(props) {
super(props);
this.state = {
volume: 70,
status: 'pause'
}
}
@haldarmahesh
haldarmahesh / getDerivedStateFromProps-react.js
Created October 19, 2018 06:34
react lifecycle 16.4 blog
static getDerivedStateFromProps(props, state) {
if (state.value !== props.value) {
return {
derivedValue: deriveValueFromProps(props),
mirroredProp: props.value
}
}
// when null is returned no update is made to the state
return null;
}
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