Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.md #90

Merged
merged 7 commits into from
Sep 12, 2024
Merged
Changes from 2 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
20 changes: 19 additions & 1 deletion apps/website/docs/factories/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,29 @@ const createCounter = createFactory(({ initialValue }) => {
### `invoke`

Anywhere in your application you can invoke a factory by calling `invoke` with a factory and its arguments:
We do not call `invoke` in components; instead, we call it in **`.js`** or **`.ts`** files, as if we were writing regular Effector code.
Prokopchuk-Valentin marked this conversation as resolved.
Show resolved Hide resolved

```ts
import { invoke } from '@withease/factories';

const counter = invoke(createCounter, { initialValue: 2 });
const { $counter, increment, decrement } = invoke(createCounter, { initialValue: 2 });
```

Now we can use `$counter`, `increment`, and `decrement` in our components
igorkamyshev marked this conversation as resolved.
Show resolved Hide resolved
Here’s how you might use them in a React component:

```jsx
const CounterComponent = () => {
const counter = useStore($counter);
Prokopchuk-Valentin marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<p>Counter: {counter}</p>
<button onClick={() => increment()}>Increment</button>
<button onClick={() => decrement()}>Decrement</button>
Prokopchuk-Valentin marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};
```

::: warning
Expand Down