Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions examples/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,29 @@ import { createMachineComponent } from "@webinargeek/machine-component"

const Count = createMachineComponent<CountMachine>({
states: {
a: {
Component: ({ actorRef }) => {
const count = useSelector(actorRef, (state) => state.context.count)
a: ({ actorRef }) => {
const count = useSelector(actorRef, (state) => state.context.count)

return (
<>
<div className="card">
<button onClick={() => actorRef.send({ type: "count" })}>
count is {count}
</button>
</div>
<div className="card">
<button onClick={() => actorRef.send({ type: "stop" })}>
Stop
</button>
</div>
</>
)
},
},
b: {
Component: ({ actorRef }) => (
<div className="card">
<button onClick={() => actorRef.send({ type: "start" })}>
Start
</button>
</div>
),
return (
<>
<div className="card">
<button onClick={() => actorRef.send({ type: "count" })}>
count is {count}
</button>
</div>
<div className="card">
<button onClick={() => actorRef.send({ type: "stop" })}>
Stop
</button>
</div>
</>
)
},
b: ({ actorRef }) => (
<div className="card">
<button onClick={() => actorRef.send({ type: "start" })}>Start</button>
</div>
),
},
})

Expand Down
6 changes: 3 additions & 3 deletions packages/machine-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ const App = () => {

### Layout components

A Component can be passed to the `Component` field of a parent state which will be rendered without being unmounted as the child states change.
A component can be passed to the `Layout` field of a parent state which will be rendered without being unmounted as the child states change.

The components defined in the child states will be passed into the `children` prop.

```tsx
const Component = createMachineComponent<MyMachine>({
states: {
a: {
Component: () => <div>A {children}</div>,
Layout: ({ children }) => <div>A {children}</div>,
states: {
b: () => <div>B</div>,
c: () => <div>C</div>,
Expand All @@ -117,7 +117,7 @@ The state components will also receive the `actorRef` prop that was passed to th
const Component = createMachineComponent<MyMachine, { foo: string }>({
states: {
a: {
Component: ({ foo }) => <div>A {foo}</div>,
Layout: ({ foo }) => <div>A {foo}</div>,
},
b: ({ foo }) => <div>B {foo}</div>,
c: ({ children, actorRef }) => {
Expand Down