-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎠webpack: add react context example
Closes #52. Signed-off-by: Dennis Reimann <mail@dennisreimann.de> new Signed-off-by: Dennis Reimann <mail@dennisreimann.de> new Signed-off-by: Dennis Reimann <mail@dennisreimann.de>
- Loading branch information
1 parent
710b536
commit 4ea60af
Showing
12 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,9 +1,9 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { hydrate } from 'react-dom' | ||
|
||
export default function clientRender (Component, props) { | ||
ReactDOM.hydrate( | ||
React.createElement(Component, props), | ||
export default (Component, props) => | ||
hydrate( | ||
<Component {...props} />, | ||
document.querySelector('#app') | ||
) | ||
} |
This file contains 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,5 +1,6 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
const React = require('react') | ||
const { renderToString } = require('react-dom/server') | ||
|
||
module.exports = function serverRender (Component, props) { | ||
return renderToString(Component(props)) | ||
} | ||
module.exports = (Component, props) => | ||
renderToString(<Component {...props} />) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
import ThemeContext, { ThemeProvider } from './ThemeContext' | ||
|
||
export default () => ( | ||
<ThemeProvider> | ||
<ThemeContext.Consumer> | ||
{context => (<h1>Context: {context}</h1>)} | ||
</ThemeContext.Consumer> | ||
</ThemeProvider> | ||
) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { Component } from 'react' | ||
|
||
const ThemeContext = React.createContext('light') | ||
|
||
export class ThemeProvider extends Component { | ||
render () { | ||
const { children, value = 'dark' } = this.props | ||
|
||
return ( | ||
<ThemeContext.Provider value={value}> | ||
{children} | ||
</ThemeContext.Provider> | ||
) | ||
} | ||
} | ||
|
||
export default ThemeContext |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
title: 'React Context' | ||
} |
4 changes: 4 additions & 0 deletions
4
test/project/src/examples/ReactContext/variants/ReactContext.jsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react' | ||
import ReactContext from '../ReactContext.jsx' | ||
|
||
export default props => <ReactContext {...props} /> |
This file contains 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 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,4 +1,3 @@ | ||
module.exports = { | ||
components: ['form'], | ||
collapsed: true | ||
components: ['form'] | ||
} |
4 changes: 4 additions & 0 deletions
4
test/project/uiengine/pages/testcases/examples/page.config.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
components: ['ReactContext'], | ||
collapsed: true | ||
} |