-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathpp_basic.js
More file actions
37 lines (31 loc) · 864 Bytes
/
pp_basic.js
File metadata and controls
37 lines (31 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react'
import ReactDOM from 'react-dom'
// Props Proxy demonstration
function PPHOC(WrappedComponent) {
return class PP extends React.Component {
render() {
const props = Object.assign({}, this.props, {
user: {
name: 'Fran',
email: 'franleplant@gmail.com'
}
})
return <WrappedComponent {...props}/>
}
}
}
class Example extends React.Component {
render() {
return (
<div>
<p>
As you can see, all original props (date), are being passed through or proxied,
and also new props (user) are being added.
</p>
<pre>{JSON.stringify(this.props, null, 2)}</pre>
</div>
)
}
}
const EnhancedExample = PPHOC(Example)
ReactDOM.render(<EnhancedExample date={(new Date).toISOString()}/>, document.getElementById('root'))