Commit a0d85d8b authored by myxvisual's avatar myxvisual Committed by Tim Neutkens

fix: Update react-uwp example support Next 3 (#2464)

* fix: Update react-uwp example support Next 3

* style: Update linted codes
parent 874f9a78
...@@ -3,11 +3,11 @@ import PropTypes from 'prop-types' ...@@ -3,11 +3,11 @@ import PropTypes from 'prop-types'
import Document, { Head, Main, NextScript } from 'next/document' import Document, { Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps ({ req }) { static getInitialProps ({ renderPage }) {
return req const {html, head, errorHtml, chunks} = renderPage()
? { userAgent: req.headers['user-agent'] } return { html, head, errorHtml, chunks }
: { userAgent: navigator.userAgent }
} }
static contextTypes = { theme: PropTypes.object }; static contextTypes = { theme: PropTypes.object };
render () { render () {
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
} from 'react-uwp' } from 'react-uwp'
class Index extends Component { class Index extends Component {
static getInitialProps ({ req }) { static async getInitialProps ({ req }) {
let userAgent let userAgent
if (process.browser) { if (process.browser) {
userAgent = navigator.userAgent userAgent = navigator.userAgent
...@@ -25,6 +25,7 @@ class Index extends Component { ...@@ -25,6 +25,7 @@ class Index extends Component {
static contextTypes = { theme: PropTypes.object } static contextTypes = { theme: PropTypes.object }
render () { render () {
const { userAgent } = this.props
return ( return (
<ThemeWrapper <ThemeWrapper
style={{ style={{
...@@ -35,12 +36,13 @@ class Index extends Component { ...@@ -35,12 +36,13 @@ class Index extends Component {
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-around' justifyContent: 'space-around'
}} }}
theme={getTheme({ userAgent: this.props.userAgent })} theme={getTheme({ userAgent })}
> >
<Button>Test Button</Button> <Button>Test Button</Button>
<DatePicker /> <DatePicker />
<ColorPicker /> <ColorPicker />
<ProgressRing size={50} /> <ProgressRing size={50} />
<p style={{ textAlign: 'center' }}>{userAgent.slice(12)}...</p>
</ThemeWrapper> </ThemeWrapper>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment