This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| export default function counterHook() { | |
| const [count, setCount] = useState(0); | |
| return ( | |
| <div> | |
| <div> | |
| <button onClick={() => setCount(count + 1)}> + Increment</button> | |
| <button onClick={() => setCount(count - 1)}> - Decrement</button> | |
| </div> | |
| <div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| export default class Counter extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| counter: 0 | |
| } | |
| this.handleCounter = this.handleCounter.bind(this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render() { | |
| return ( | |
| <div> | |
| <Brick/> <Brick/> <Brick/> <Brick/> <Brick/> <Brick/> <Brick/> <Brick/> | |
| <Brick/> <Brick/> <Brick/> <Brick/> | |
| </div> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| componentWillUnmount() { | |
| this.chart.destroy(); | |
| this.resetLocalStorage(); | |
| this.clearSession(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Snapshot = number | null; | |
| class ScrollingList extends React.Component<Props, State, Snapshot> { | |
| listRef = React.createRef(); | |
| getSnapshotBeforeUpdate( | |
| prevProps: Props, | |
| prevState: State | |
| ): Snapshot { | |
| // Are we adding new items to the list? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shouldComponentUpdate(nextProps, nextState) { | |
| let shouldUpdate = this.props.status !== nextProps.status; | |
| return shouldUpdate; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render() { | |
| <div> | |
| <PlayHeader> | |
| <Status/> | |
| <VolumeBar/> | |
| <SeekBar/> | |
| </PlayHeader> | |
| </div> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ContraMusicPlayer extends React.Component | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| volume: 70, | |
| status: 'pause' | |
| } | |
| } |