innerRef
ref
Sometimes you need access to the
ref
of the underlying component that's rendered. You can accomplish this with
the innerRef
prop.
This is a function and if provided, will be called with the inner element's reference.
Often you'll bring glamorous
into an existing project which is already
using global CSS. Many of the glamorous
APIs make working with this
as easy as possible.
html
/body
or add some reset
styles), you wont do this with
glamorous
. Instead you can use regular CSS or use glamor's API for
injecting global styles.
In addition, rather than using CSS to style an a
tag with global CSS,
you should create a Link
component with all the styles you need and
reuse that.
// TODO
If your use case is really size constrained, then you might consider using the "tiny" version of glamorous for your application.
It is a miniature version of glamorous
with a few limitations:
glamorous.article({/* styles */ })
)
So you have to create your own (glamorous('article')({/* styles */ })
)glamorous.Span
)glam
prop (see the example below).ThemeProvider
or withTheme
, you must import those manually.
They are not exported as part of glamorous/ tiny
like they are with glamorous
.Here's an example of what you're able to do with it.
import React from 'react'
import glamorous from 'glamorous/dist/glamorous.es.tiny'
const Comp = glamorous('div')({
color: 'red'
}, (props) => ({
fontSize: props.glam.big ? 20 : 12
}))
function Root() {
return (
<Comp
glam={{ big: true }}
thisWillBeForwardedAndReactWillWarn
>
ciao
</Comp>
)
}
export default Root
babel-plugin-module-resolver
or the resolve.alias
config with webpack so you don't have
to import from that full path.
You have the following options available for this import:
glamorous/dist/glamorous.es.tiny.js
- use if you're using Webpack@>=2 or Rollupglamorous/dist/glamorous.cjs.tiny.js
- use if you're not transpiling ESModulesglamorous/dist/glamorous.umd.tiny.js
- use if you're including it as a script tag. (There's also a .min.js
version).Because both glamor
and react
support SSR, glamorous does too! I actually do this
on my personal site which is generated at build-time
on the server. Learn about rendering
react
on the server and
glamor
too.