-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
45 lines (39 loc) · 1.05 KB
/
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
40
41
42
43
44
45
// How to integrate with 3rd party libs?
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { StyleProvider } from 'cf-style-provider';
import { createComponent, withRenderer } from 'cf-style-container';
const styles = () => ({
height: 100,
width: 100,
border: '4px solid blue',
padding: '2rem',
fontSize: '1.5rem',
margin: '2rem'
});
const Square = createComponent(styles);
// typical way how to integrate
const getMarkupString = renderer => {
const className = renderer.renderRule(styles);
return `
<h4>React in React</h4>
<div class="${className}">square?</div>
`;
};
// better way (escaping is on!)
const getMarkup = renderer => {
return ReactDOMServer.renderToStaticMarkup(
<StyleProvider renderer={renderer}>
<div>
<h4>React in React</h4>
<Square>squareeee?</Square>
</div>
</StyleProvider>
);
};
export default withRenderer(({ renderer }) =>
<article>
<h1>12. Integration</h1>
<div dangerouslySetInnerHTML={{ __html: getMarkup(renderer) }} />
</article>
);