styletron-inferno
Styletron bindings for Inferno.
Provider
Provider
is a component that exposes a styletron
instance to child components on their context
.
An instance of styletron-server
or styletron-client
must be passed to Provider
as a styletron
prop.
Server-side Example
;;;;; { const styletron = ; const root = ; // NOTE: getStylesheetsHtml must be called after renderToString const stylesheets = styletron; return ` <!DOCTYPE html> <html> <head> </head> <body> <div id="root"></div> </body> </html> `;} const app = ;app;
Client-side Example
;;;; const stylesheets = document;const styletron = stylesheets; ;
styled(name, styles)
const StyledComponent = styled(
name: string|function,
styles: object|function
):VNode
name
can be a string
to create a styled element, or it can be a class|function
component.
styles
can be an object
with CSS property/value pairs, or it can be a function
that returns an object
with CSS property/value pairs. When a function
is passed, it is called with props
and context
.
; const StaticStyledDiv = ; const DynamicStyledDiv = ; const ComposedStyledDiv = ; Inferno;
If you want a ref
to the inner DOMElement
or rendered Component
instance, a special innerRef
prop is provided. innerRef
must be a function—string refs are not supported.
NOTE: ref
does not work with functional components since they are stateless.
const StyledDiv = ; { console; } { return <StyledDiv innerRef= thisstyledDiv = el/> }