react-alpine-store

1.0.5 • Public • Published

Allows for syncing between reactive state across React and Alpine's $store. See more information about Alpine's $store here.

Useful for projects that require both frameworks, such as an Alpine application within Astro that needs to drop in some React components.

Usage

// main.js
document.addEventListener("alpine:init", () => {
  Alpine.store("customThing", {
    count: 0;
  });
});
// Counter.jsx
import { useAlpineStore } from "react-alpine-store"

export default function Counter() {
  const [ count, setCount ] = useAlpineStore("customThing.count");

  return (
    <div>
      <p>React Value: {count}</p>
      <br/>
      <button onClick={() => setCount(count + 1)}>React Increment</button>
      <br/>
      <p>Alpine Value: <span x-text="$store.customThing.count"></span></p>
      <br/>
      <button x-on:click="$store.customThing.count++">Alpine Increment</button>
    </div>
  )
}

Package Sidebar

Install

npm i react-alpine-store

Weekly Downloads

10

Version

1.0.5

License

ISC

Unpacked Size

2.2 kB

Total Files

3

Last publish

Collaborators

  • elias-michaias