@unitedstatespowersquadrons/components 1.1.2 → 1.2.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -16,6 +16,30 @@ Install dependencies with
16
16
  yarn
17
17
  ```
18
18
 
19
+ ## Mounting Components
20
+
21
+ Components can be mounted by passing them into the included `mount` function in
22
+ your application asset root.
23
+
24
+ ```tsx
25
+ mount({
26
+ ActionButton,
27
+ });
28
+ ```
29
+
30
+ This will search the DOM for elements matching the following pattern, and
31
+ attempt to render the corresponding component at that location.
32
+
33
+ ```html
34
+ <div data-react-component="Namespace.Component" data-props="{}"></div>
35
+ ```
36
+
37
+ In Rails, you can generate this element with the following helper call:
38
+
39
+ ```rb
40
+ content_tag(:div, '', data: { 'react-component' => component_name, props: props.to_json })
41
+ ```
42
+
19
43
  ## Toasts
20
44
 
21
45
  More detailed information is available for [Toasts](Toasts/Readme.md) usage.
@@ -1,4 +1,3 @@
1
- import { createContext } from "react";
2
1
  import { Draft } from "immer";
3
2
  import * as ReducerHandlers from "./reducerHandlers";
4
3
  import { AppState, ServerResponse } from "./types";
@@ -27,9 +26,4 @@ export const reducer = (draft: Draft<AppState>, action: AppAction): void => {
27
26
  }
28
27
  };
29
28
 
30
- const StateContext = createContext<AppState | null>(null);
31
- const DispatchContext = createContext<React.Dispatch<AppAction> | null>(null);
32
- const handlers = Object.values(ReducerHandlers);
33
-
34
- export const { AppProvider, useAppDispatch, useAppState } =
35
- buildReducer(reducer, StateContext, DispatchContext, handlers);
29
+ export const { AppProvider, useAppDispatch, useAppState } = buildReducer(reducer, Object.values(ReducerHandlers));
@@ -1,4 +1,4 @@
1
- import React, { useContext, useMemo } from "react";
1
+ import React, { createContext, useContext, useMemo } from "react";
2
2
  import { Draft, produce } from "immer";
3
3
  import { useImmerReducer } from "use-immer";
4
4
  import { ReducerHandler } from "./types";
@@ -10,10 +10,11 @@ interface InitialAppProps<AppState> {
10
10
 
11
11
  export default function buildReducer<AppState, AppAction>(
12
12
  reducer: (draft: Draft<AppState>, action: AppAction) => void,
13
- StateContext: React.Context<AppState | null>,
14
- DispatchContext: React.Context<React.Dispatch<AppAction> | null>,
15
13
  handlers: ReducerHandler<AppAction>[] = []
16
14
  ) {
15
+ const StateContext = createContext<AppState | null>(null);
16
+ const DispatchContext = createContext<React.Dispatch<AppAction> | null>(null);
17
+
17
18
  function AppProvider(props: InitialAppProps<AppState>) {
18
19
  const [providerState, dispatch] = useImmerReducer(reducer, props.initialState, (state: AppState) => {
19
20
  return produce(state, draft => draft);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.1.2",
3
+ "version": "1.2.0-pre.1",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {