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

Support dynamic store prop on component stores #2714

Merged
merged 9 commits into from Aug 23, 2023
Merged

Conversation

diegohaz
Copy link
Member

@diegohaz diegohaz commented Aug 20, 2023

This PR introduces the ability for the dynamic store prop on component store hooks to change between renders. In other words, one store can be passed to another store using the store prop to keep them in sync. While this functionality is already supported, this PR enhances its adaptability between renders. This enhancement should simplify the implementation of #2658.

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2023

🦋 Changeset detected

Latest commit: 11be224

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@ariakit/react-core Minor
@ariakit/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Aug 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
ariakit ❌ Failed (Inspect) Aug 23, 2023 8:46pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
reakit ⬜️ Ignored (Inspect) Visit Preview Aug 23, 2023 8:46pm

@diegohaz diegohaz changed the title store dynamic prop Support dynamic store prop on component stores Aug 20, 2023
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 20, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 11be224:

Sandbox Source
Ariakit Configuration

@diegohaz diegohaz merged commit a3628e5 into main Aug 23, 2023
13 of 14 checks passed
@diegohaz diegohaz deleted the store-dynamic-prop branch August 23, 2023 20:30
@github-actions github-actions bot mentioned this pull request Aug 23, 2023
diegohaz pushed a commit that referenced this pull request Sep 6, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @ariakit/core@0.3.0

### Minor Changes

- [`#2783`](#2783) **BREAKING**
_(This should affect very few people)_: The `select` and `menu` props on
`useComboboxStore` have been removed. If you need to compose `Combobox`
with `Select` or `Menu`, use the `combobox` prop on `useSelectStore` or
`useMenuStore` instead.

- [`#2745`](#2745) Component
stores will now throw an error if they receive another store prop in
conjunction with default prop values.

### Patch Changes

- [`#2782`](#2782) Fixed form
store not synchrozining validate and submit callbacks with another form
store through the `store` property.

- [`#2783`](#2783) Component
store objects now contain properties for the composed stores passed to
them as props. For instance, `useSelectStore({ combobox })` will return
a `combobox` property if the `combobox` prop is specified.

- [`#2785`](#2785) Added `parent`
and `menubar` properties to the menu store. These properties are
automatically set when rendering nested menus or menus within a menubar.

Now, it also supports rendering nested menus that aren't nested in the
React tree. In this case, you would have to supply the parent menu store
manually to the child menu store.

These properties are also included in the returned menu store object,
allowing you to verify whether the menu is nested. For instance:

    ```jsx
    const menu = useMenuStore(props);
    const isNested = Boolean(menu.parent);
    ```

- [`#2796`](#2796) Composed store
props such as `useSelectStore({ combobox })` now accept `null` as a
value.

## @ariakit/react@0.3.0

### Minor Changes

- [`#2714`](#2714) Added support
for a dynamic `store` prop on component stores.

This is similar to the `store` prop on components, keeping both stores
in sync. Now, component store hooks can support modifying the value of
the `store` prop after the initial render. For instance:

    ```js
    // props.store can change between renders now
    const checkbox = useCheckboxStore({ store: props.store });
    ```

When the `store` prop changes, the object returned from the store hook
will update as well. Consequently, effects and hooks that rely on the
store will re-run.

While it's unlikely, this **could represent a breaking change** if
you're depending on the `store` prop in component stores to only
acknowledge the first value passed to it.

- [`#2783`](#2783) **BREAKING**
_(This should affect very few people)_: The `combobox` state on
`useSelectStore` has been replaced by the `combobox` property on the
store object.

    **Before:**

    ```js
    const combobox = useComboboxStore();
    const select = useSelectStore({ combobox });
    const hasCombobox = select.useState("combobox");
    ```

    **After:**

    ```js
    const combobox = useComboboxStore();
    const select = useSelectStore({ combobox });
    const hasCombobox = Boolean(select.combobox);
    ```

In the example above, `select.combobox` is literally the same as the
`combobox` store. It will be defined if the `combobox` store is passed
to `useSelectStore`.

- [`#2783`](#2783) **BREAKING**
_(This should affect very few people)_: The `select` and `menu` props on
`useComboboxStore` have been removed. If you need to compose `Combobox`
with `Select` or `Menu`, use the `combobox` prop on `useSelectStore` or
`useMenuStore` instead.

- [`#2717`](#2717) The `children`
prop as a function has been deprecated on all components. Use the
[`render`](https://ariakit.org/guide/composition#explicit-render-function)
prop instead.

- [`#2717`](#2717) The `as` prop
has been deprecated on all components. Use the
[`render`](https://ariakit.org/guide/composition) prop instead.

- [`#2717`](#2717) The
`backdropProps` prop has been deprecated on `Dialog` and derived
components. Use the
[`backdrop`](https://ariakit.org/reference/dialog#backdrop) prop
instead.

- [`#2745`](#2745) Component
stores will now throw an error if they receive another store prop in
conjunction with default prop values.

### Patch Changes

- [`#2737`](#2737) Fixed
controlled component stores rendering with a stale state.

- [`#2783`](#2783) Component
store objects now contain properties for the composed stores passed to
them as props. For instance, `useSelectStore({ combobox })` will return
a `combobox` property if the `combobox` prop is specified.

- [`#2785`](#2785) Added `parent`
and `menubar` properties to the menu store. These properties are
automatically set when rendering nested menus or menus within a menubar.

Now, it also supports rendering nested menus that aren't nested in the
React tree. In this case, you would have to supply the parent menu store
manually to the child menu store.

These properties are also included in the returned menu store object,
allowing you to verify whether the menu is nested. For instance:

    ```jsx
    const menu = useMenuStore(props);
    const isNested = Boolean(menu.parent);
    ```

- [`#2795`](#2795) Updated the
`Menu` component so the `composite` and `typeahead` props are
automatically set to `false` when combining it with a `Combobox`
component.

This means you'll not need to explicitly pass `composite={false}` when
building a [Menu with
Combobox](https://ariakit.org/examples/menu-combobox) component.

- [`#2796`](#2796) Composed store
props such as `useSelectStore({ combobox })` now accept `null` as a
value.

-   Updated dependencies: `@ariakit/react-core@0.3.0`.

## @ariakit/react-core@0.3.0

### Minor Changes

- [`#2714`](#2714) Added support
for a dynamic `store` prop on component stores.

This is similar to the `store` prop on components, keeping both stores
in sync. Now, component store hooks can support modifying the value of
the `store` prop after the initial render. For instance:

    ```js
    // props.store can change between renders now
    const checkbox = useCheckboxStore({ store: props.store });
    ```

When the `store` prop changes, the object returned from the store hook
will update as well. Consequently, effects and hooks that rely on the
store will re-run.

While it's unlikely, this **could represent a breaking change** if
you're depending on the `store` prop in component stores to only
acknowledge the first value passed to it.

- [`#2714`](#2714) **BREAKING**:
The `useStore` function exported by `@ariakit/react-core/utils/store`
has been updated.

- [`#2760`](#2760) **BREAKING**:
The `useStoreState` function exported by
`@ariakit/react-core/utils/store` has been updated so it'll always run
the selector callback even when the passed store is `null` or
`undefined`.

- [`#2783`](#2783) **BREAKING**
_(This should affect very few people)_: The `combobox` state on
`useSelectStore` has been replaced by the `combobox` property on the
store object.

    **Before:**

    ```js
    const combobox = useComboboxStore();
    const select = useSelectStore({ combobox });
    const hasCombobox = select.useState("combobox");
    ```

    **After:**

    ```js
    const combobox = useComboboxStore();
    const select = useSelectStore({ combobox });
    const hasCombobox = Boolean(select.combobox);
    ```

In the example above, `select.combobox` is literally the same as the
`combobox` store. It will be defined if the `combobox` store is passed
to `useSelectStore`.

- [`#2783`](#2783) **BREAKING**
_(This should affect very few people)_: The `select` and `menu` props on
`useComboboxStore` have been removed. If you need to compose `Combobox`
with `Select` or `Menu`, use the `combobox` prop on `useSelectStore` or
`useMenuStore` instead.

- [`#2717`](#2717) The `children`
prop as a function has been deprecated on all components. Use the
[`render`](https://ariakit.org/guide/composition#explicit-render-function)
prop instead.

- [`#2717`](#2717) The `as` prop
has been deprecated on all components. Use the
[`render`](https://ariakit.org/guide/composition) prop instead.

- [`#2717`](#2717) The
`backdropProps` prop has been deprecated on `Dialog` and derived
components. Use the
[`backdrop`](https://ariakit.org/reference/dialog#backdrop) prop
instead.

- [`#2745`](#2745) Component
stores will now throw an error if they receive another store prop in
conjunction with default prop values.

### Patch Changes

- [`#2737`](#2737) Fixed
controlled component stores rendering with a stale state.

- [`#2758`](#2758) Added
`CheckboxProvider` component and `useCheckboxContext` hook.

- [`#2759`](#2759) Added
`CollectionProvider` component and `useCollectionContext` hook.

- [`#2769`](#2769) Added
`DisclosureProvider` component and `useDisclosureContext` hook.

- [`#2770`](#2770) Added
`CompositeProvider` component and `useCompositeContext` hook.

- [`#2771`](#2771) Added
`DialogProvider` component and `useDialogContext` hook.

- [`#2774`](#2774) Added
`PopoverProvider` component and `usePopoverContext` hook.

- [`#2775`](#2775) Added
`ComboboxProvider` component and `useComboboxContext` hook.

- [`#2776`](#2776) Added
`SelectProvider` component and `useSelectContext` hook.

- [`#2777`](#2777) Added
`RadioProvider` component and `useRadioContext` hook.

- [`#2778`](#2778) Added
`HovercardProvider` component and `useHovercardContext` hook.

- [`#2779`](#2779) Added
`TabProvider` component and `useTabContext` hook.

- [`#2780`](#2780) Added
`ToolbarProvider` component and `useToolbarContext` hook.

- [`#2781`](#2781) Added
`TooltipProvider` component and `useTooltipContext` hook.

- [`#2782`](#2782) Added
`FormProvider` component and `useFormContext` hook.

- [`#2783`](#2783) Component
store objects now contain properties for the composed stores passed to
them as props. For instance, `useSelectStore({ combobox })` will return
a `combobox` property if the `combobox` prop is specified.

- [`#2785`](#2785) Added
`MenuProvider` component and `useMenuContext` hook.

- [`#2785`](#2785) Added
`MenuBarProvider` component and `useMenuBarContext` hook.

- [`#2785`](#2785) Added `parent`
and `menubar` properties to the menu store. These properties are
automatically set when rendering nested menus or menus within a menubar.

Now, it also supports rendering nested menus that aren't nested in the
React tree. In this case, you would have to supply the parent menu store
manually to the child menu store.

These properties are also included in the returned menu store object,
allowing you to verify whether the menu is nested. For instance:

    ```jsx
    const menu = useMenuStore(props);
    const isNested = Boolean(menu.parent);
    ```

- [`#2794`](#2794) The `combobox`
prop on `useSelectStore` is now automatically set based on the context.

- [`#2795`](#2795) Updated the
`Menu` component so the `composite` and `typeahead` props are
automatically set to `false` when combining it with a `Combobox`
component.

This means you'll not need to explicitly pass `composite={false}` when
building a [Menu with
Combobox](https://ariakit.org/examples/menu-combobox) component.

- [`#2795`](#2795) The `combobox`
prop on `useMenuStore` is now automatically set based on the context.

- [`#2796`](#2796) Composed store
props such as `useSelectStore({ combobox })` now accept `null` as a
value.

-   Updated dependencies: `@ariakit/core@0.3.0`.

## @ariakit/test@0.2.3

### Patch Changes

-   Updated dependencies: `@ariakit/core@0.3.0`.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant