-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (34 loc) · 853 Bytes
/
index.js
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
38
39
import React from 'react';
import ReactDom from 'react-dom/server';
import { getDataFromTree } from 'react-apollo';
const { Provider, Consumer } = React.createContext({ parent: '' });
const Node = (props) => (
<Consumer>
{({ parent }) => {
console.log(`ID: ${props.id} | PARENT: ${parent}`)
return (
<div>
<Provider value={{parent: parent ? `${parent}/${props.id}` : props.id }}>
{props.children}
</Provider>
</div>
)
}}
</Consumer>
)
const App = (
<Node id='root'>
<Node id='one'>
<Node id='a' />
<Node id='b' />
</Node>
<Node id='two'>
<Node id='a' />
<Node id='b' />
</Node>
</Node>
)
console.log('without getDataFromTree:')
ReactDom.renderToStaticMarkup(App);
console.log('\nduring getDataFromTree:')
getDataFromTree(App)