You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/react-jss-hoc.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,22 @@
1
-
##JSS HOC for React
1
+
# JSS HOC for React
2
2
3
3
-[Basic](#basic)
4
-
-[Server-side rendering](#server-side-rendering)
4
+
-[Accessing the theme inside the styled component](#accessing-the-theme-inside-the-styled-component)
5
+
-[Accessing the theme without a styled component](#accessing-the-theme-without-a-styled-component)
5
6
-[The inner component](#the-inner-component)
6
7
-[The inner ref](#the-inner-ref)
7
8
-[Decorators](#decorators)
9
+
-[Injection order](#injection-order)
8
10
-[Usage with TypeScript](#usage-with-typescript)
9
11
10
-
###Usage
12
+
## Usage
11
13
12
14
React-JSS wraps your component with a [higher-order component](https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750).
13
15
It injects a `classes` prop, which is a simple map of rule names and generated class names.
14
16
15
17
Try it out in the [playground](https://codesandbox.io/s/j3l06yyqpw).
16
18
17
-
####Basic
19
+
## Basic
18
20
19
21
```javascript
20
22
importReactfrom'react'
@@ -88,7 +90,7 @@ and
88
90
}
89
91
```
90
92
91
-
####Accessing the theme inside the styled component
93
+
## Accessing the theme inside the styled component
92
94
93
95
The theme will not be injecting into the wrapped component.
94
96
To inject the theme into the wrapped component, pass the `injectTheme` option to `withStyles`.
####Accessing the theme without a styled component
124
+
## Accessing the theme without a styled component
123
125
124
126
In case you need to access the theme but not render any CSS, you can also use `withTheme`. It is a Higher-order Component factory which takes a `React.Component` and maps the theme object from context to props. [Read more about `withTheme` in `theming`'s documentation.](https://github.com/cssinjs/theming#withthemecomponent)
125
127
@@ -130,7 +132,7 @@ import {withTheme} from 'react-jss'
130
132
constButton=withTheme(({theme}) =><button>I can access {theme.colorPrimary}</button>)
console.log(StyledComponent.InnerComponent) // Prints out the inner component.
141
143
```
142
144
143
-
####The inner ref
145
+
## The inner ref
144
146
145
147
To get a `ref` to the inner element, use the `ref` prop.
146
148
We will forward the ref to the inner component.
@@ -161,7 +163,7 @@ const App = (
161
163
)
162
164
```
163
165
164
-
####Decorators
166
+
## Decorators
165
167
166
168
_Beware that [decorators are stage-2 proposal](https://tc39.github.io/proposal-decorators/), so there are [no guarantees that decorators will make its way into language specification](https://tc39.github.io/process-document/). Do not use it in production. Use it at your own risk and only if you know what you are doing._
167
169
@@ -195,7 +197,7 @@ class Button extends Component {
195
197
exportdefaultButton
196
198
```
197
199
198
-
###Injection order
200
+
## Injection order
199
201
200
202
Injection of style tags happens in the same order as the `withStyles()` invocation.
201
203
Source order specificity is higher the lower style tag is in the tree. Therefore you should call `withStyles` of components you want to override first.
Copy file name to clipboardExpand all lines: docs/react-jss.md
+28-26Lines changed: 28 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
##JSS integration with React
1
+
# JSS integration with React
2
2
3
3
React-JSS integrates [JSS](https://github.com/cssinjs/jss) with React using the new Hooks API as well as a Styled Component API. JSS and the [default preset](https://github.com/cssinjs/jss/tree/master/packages/jss-preset-default) are already built in.
4
4
@@ -14,27 +14,29 @@ Benefits compared to using the core JSS package directly:
14
14
- The static part of a Style Sheet will be shared between all elements.
15
15
- Function values and rules are updated automatically with props as an argument.
16
16
17
-
###Table of Contents
17
+
## Table of Contents
18
18
19
19
-[Install](#install)
20
-
-[Usage](#usage)
21
-
-[Basic](#basic)
22
-
-[Dynamic Values](#dynamic-values)
23
-
-[Theming](#theming)
24
-
-[Server-side rendering](#server-side-rendering)
25
-
-[React tree traversing](#react-tree-traversing)
26
-
-[Custom setup](#custom-setup)
27
-
-[TypeScript](#typescript)
28
-
29
-
### Install
20
+
-[Basic](#basic)
21
+
-[Dynamic Values](#dynamic-values)
22
+
-[Theming](#theming)
23
+
-[Accessing the theme inside the styled component](#accessing-the-theme-inside-the-styled-component)
24
+
-[Accessing the theme without styles](#accessing-the-theme-without-styles)
You can use [function values](jss-syntax.md#function-values), Function rules and observables out of the box. Function values and function rules will receive a props object once the component receives new props or mounts for the first time.
112
114
@@ -174,7 +176,7 @@ and
174
176
}
175
177
```
176
178
177
-
####Theming
179
+
## Theming
178
180
179
181
The idea is that you define a theme, wrap your application with `ThemeProvider` and pass the `theme` object to `ThemeProvider`. Later you can access theme in your styles creator function and using a `useTheme()` hook. After that, you may change your theme, and all your components will get the new theme automatically.
180
182
@@ -222,7 +224,7 @@ const App = () => (
222
224
)
223
225
```
224
226
225
-
####Accessing the theme inside the styled component
227
+
## Accessing the theme inside the styled component
226
228
227
229
Use `useTheme()` hook to access the theme inside of the function component.
In case you need to access the theme without rendering any CSS, you can also use `useTheme()` standalone.
259
261
@@ -267,7 +269,7 @@ const Button = () => {
267
269
}
268
270
```
269
271
270
-
####Using custom Theming Context
272
+
## Using custom Theming Context
271
273
272
274
Use _namespaced_ themes so that a set of UI components gets no conflicts with another set of UI components from a different library also using `react-jss` or in case you want to use the same theme from another context that is already used in your app.
273
275
@@ -318,7 +320,7 @@ const App = () => (
318
320
)
319
321
```
320
322
321
-
####Server-side rendering
323
+
## Server-side rendering
322
324
323
325
After the application is mounted, you should remove the style tag used by critical CSS rendered server-side.
324
326
@@ -354,7 +356,7 @@ export default function render(req, res) {
354
356
}
355
357
```
356
358
357
-
####React tree traversing
359
+
## React tree traversing
358
360
359
361
For traversing the React tree outside of the HTML rendering, you should add `disableStylesGeneration` property.
360
362
@@ -380,7 +382,7 @@ async function main() {
380
382
main()
381
383
```
382
384
383
-
####Custom setup
385
+
## Custom setup
384
386
385
387
If you want to specify a JSS version and plugins to use, you should create your [own JSS instance](https://github.com/cssinjs/jss/blob/master/docs/jss-api.md#create-an-own-jss-instance), [setup plugins](https://github.com/cssinjs/jss/blob/master/docs/setup.md#setup-with-custom-plugins) and pass it to `JssProvider`.
386
388
@@ -407,7 +409,7 @@ You can also access the default JSS instance.
407
409
import {jss} from'react-jss'
408
410
```
409
411
410
-
####Multi-tree setup
412
+
## Multi-tree setup
411
413
412
414
In case you render multiple react rendering trees in one application, you will get class name collisions because every JssProvider rerender will reset the class names generator. If you want to avoid this, you can share the class names generator between multiple JssProvider instances.
413
415
@@ -455,7 +457,7 @@ const Component = () => (
455
457
)
456
458
```
457
459
458
-
###Injection order
460
+
## Injection order
459
461
460
462
Injection of style tags happens in the same order as the `createUseStyles()` invocation.
461
463
Source order specificity is higher the lower style tag is in the tree. Therefore you should call `createUseStyles` of components you want to override first.
0 commit comments