new Provider()
- Source:
Properties:
Name | Type | Description |
---|---|---|
styletron |
object | Styletron instance |
children |
InfernoElement | Child nodes |
Provides a Styletron instance to descendant styled components via context
Examples
// Server
import StyletronServer from 'styletron-server';
import { renderToString } from 'inferno-server';
import { Provider } from 'styletron-inferno';
import App from '../shared/components/app';
function render() {
const styletron = new StyletronServer();
const root = renderToString(
<Provider styletron={styletron}>
<App/>
</Provider>
);
const stylesheets = styletron.getStylesheetsHtml('my-custom-class');
return `
<!DOCTYPE html>
<html>
<head>
${stylesheets}
</head>
<body>
<div id="root">${root}</div>
</body>
</html>
`;
}
// Client
import Inferno from 'inferno';
import StyletronClient from 'styletron-client';
import { Provider } from 'styletron-inferno';
import App from '../shared/components/app';
function render() {
const stylesheets = document.getElementsByClassName('my-custom-class');
const styletron = new StyletronClient(stylesheets);
Inferno.render((
<Provider styletron={styletron}>
<App/>
</Provider>
), document.getElementsById('root'));
}
Extends
- InfernoComponent