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
| const {deepEqual} = require('assert').strict; | |
| const testCase1 = `AA00 = 10 | |
| AA01 = AA00 + AB00 | |
| AB00 = 15`; | |
| const testCase2 = `AA00 = 10 | |
| AB00 = (AA00 + AA01) * 15 | |
| AA01 = 20 + AB00`; |
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
| TypeScript 22 hrs 49 mins █████████▉░░░░░░░░░░░ 47.4% | |
| Other 20 hrs 16 mins ████████▊░░░░░░░░░░░░ 42.1% | |
| JSX 2 hrs 4 mins ▉░░░░░░░░░░░░░░░░░░░░ 4.3% | |
| JSON 1 hr 38 mins ▋░░░░░░░░░░░░░░░░░░░░ 3.4% | |
| JavaScript 1 hr 7 mins ▍░░░░░░░░░░░░░░░░░░░░ 2.3% |
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 memoize from "memoize-one"; | |
| class Example extends Component { | |
| // State only needs to hold the current filter text value: | |
| state = { filterText: "" }; | |
| // Re-run the filter whenever the list array or filter text changes: | |
| filter = memoize( | |
| (list, filterText) => list.filter(item => item.text.includes(filterText)) | |
| ); |
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
| // PureComponents only rerender if at least one state or prop value changes. | |
| // Change is determined by doing a shallow comparison of state and prop keys. | |
| class Example extends PureComponent { | |
| // State only needs to hold the current filter text value: | |
| state = { | |
| filterText: "" | |
| }; | |
| handleChange = event => { | |
| this.setState({ filterText: event.target.value }); |
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 Example extends Component { | |
| state = { | |
| filterText: "", | |
| }; | |
| // ******************************************************* | |
| // NOTE: this example is NOT the recommended approach. | |
| // See the examples below for our recommendations instead. | |
| // ******************************************************* |
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 EmailInput extends Component { | |
| state = { | |
| email: this.props.defaultEmail, | |
| prevPropsUserID: this.props.userID | |
| }; | |
| static getDerivedStateFromProps(props, state) { | |
| // Any time the current user changes, | |
| // Reset any parts of state that are tied to that user. | |
| // In this simple example, that's just the email. |
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
| <EmailInput | |
| defaultEmail={this.props.user.email} | |
| key={this.props.user.id} | |
| /> |
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 EmailInput extends Component { | |
| state = { email: this.props.defaultEmail }; | |
| handleChange = event => { | |
| this.setState({ email: event.target.value }); | |
| }; | |
| render() { | |
| return <input onChange={this.handleChange} value={this.state.email} />; | |
| } |
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
| function EmailInput(props) { | |
| return <input onChange={props.onChange} value={props.email} />; | |
| } |
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 EmailInput extends Component { | |
| state = { | |
| email: this.props.defaultEmail | |
| }; | |
| resetEmailForNewUser(newEmail) { | |
| this.setState({ email: newEmail }); | |
| } | |
| // ... |
NewerOlder