Skip to content

Commit

Permalink
refactor: update createZustandContext to use createElement instead of…
Browse files Browse the repository at this point in the history
… cloneElement

- Replaced the use of `cloneElement` with `createElement` in the `createZustandContext` function
- This change simplifies the code and aligns with the recommended React API usage
  • Loading branch information
Ryan-Zayne committed Oct 5, 2024
1 parent ff970ab commit 7b2eb0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/lovely-birds-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@zayne-labs/toolkit": patch
---

refactor: update createZustandContext to use createElement instead of cloneElement

- Replaced the use of `cloneElement` with `createElement` in the `createZustandContext` function
- This change simplifies the code and aligns with the recommended React API usage
4 changes: 2 additions & 2 deletions src/react/zustand/createZustandContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SelectorFn } from "@/type-helpers";
import { cloneElement } from "react";
import { createElement } from "react";
import type { StoreApi, UseBoundStore } from "zustand";
import { type CustomContextOptions, createCustomContext, useConstant } from "../hooks";

Expand Down Expand Up @@ -28,7 +28,7 @@ const createZustandContext = <
"createStore" in restOfProps ? restOfProps.createStore() : restOfProps.value
);

return cloneElement(Provider as never, { value: useZustandStore }, children) as React.ReactNode;
return createElement(Provider, { value: useZustandStore }, children);
}

const useBoundStore = <TResult>(selector: SelectorFn<TState, TResult>) => useCustomContext()(selector);
Expand Down

0 comments on commit 7b2eb0e

Please sign in to comment.