-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Clarify DOM container in homepage examples #1526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: A Component Using External Plugins | ||
| order: 3 | ||
| domid: markdown-example | ||
| --- | ||
|
|
||
| React is flexible and provides hooks that allow you to interface with other libraries and frameworks. This example uses **remarkable**, an external Markdown library, to convert the `<textarea>`'s value in real time. |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: A Stateful Component | ||
| order: 1 | ||
| domid: timer-example | ||
| --- | ||
|
|
||
| In addition to taking input data (accessed via `this.props`), a component can maintain internal state data (accessed via `this.state`). When a component's state data changes, the rendered markup will be updated by re-invoking `render()`. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| --- | ||
| title: An Application | ||
| order: 2 | ||
| domid: todos-example | ||
| --- | ||
|
|
||
| Using `props` and `state`, we can put together a small Todo application. This example uses `state` to track the current list of items as well as the text that the user has entered. Although event handlers appear to be rendered inline, they will be collected and implemented using event delegation. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,6 @@ class CodeEditor extends Component { | |
| } | ||
|
|
||
| componentDidMount() { | ||
| // Initial render() will always be a no-op, | ||
| // Because the mountNode ref won't exist yet. | ||
| this._render(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this would still not work on first render if parents weren't already in the documented. I can add a setTimeout but don't care enough about this (?) If this breaks I'm pretty sure we'd notice that fast. |
||
| } | ||
|
|
||
|
|
@@ -45,7 +43,7 @@ class CodeEditor extends Component { | |
| } | ||
|
|
||
| render() { | ||
| const {children} = this.props; | ||
| const {children, containerNodeID} = this.props; | ||
| const { | ||
| compiledES6, | ||
| code, | ||
|
|
@@ -205,6 +203,7 @@ class CodeEditor extends Component { | |
| <MetaTitle>Result</MetaTitle> | ||
| </div> | ||
| <div | ||
| id={containerNodeID} | ||
| css={{ | ||
| padding: 10, | ||
| maxHeight: '340px !important', | ||
|
|
@@ -233,7 +232,6 @@ class CodeEditor extends Component { | |
| padding: 5, | ||
| }, | ||
| }} | ||
| ref={this._setMountRef} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
@@ -243,21 +241,16 @@ class CodeEditor extends Component { | |
| } | ||
|
|
||
| _render() { | ||
| if (!this._mountNode) { | ||
| return; | ||
| } | ||
|
|
||
| const {compiled} = this.state; | ||
|
|
||
| try { | ||
| // Example code requires React, ReactDOM, and Remarkable to be within scope. | ||
| // It also requires a "mountNode" variable for ReactDOM.render() | ||
| // eslint-disable-next-line no-new-func | ||
| new Function('React', 'ReactDOM', 'Remarkable', 'mountNode', compiled)( | ||
| new Function('React', 'ReactDOM', 'Remarkable', compiled)( | ||
| React, | ||
| ReactDOM, | ||
| Remarkable, | ||
| this._mountNode, | ||
| ); | ||
| } catch (error) { | ||
| console.error(error); | ||
|
|
@@ -269,10 +262,6 @@ class CodeEditor extends Component { | |
| } | ||
| } | ||
|
|
||
| _setMountRef = ref => { | ||
| this._mountNode = ref; | ||
| }; | ||
|
|
||
| _updateState(code, showJSX = true) { | ||
| try { | ||
| let newState = { | ||
|
|
||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect