Skip to content

elias-michaias/react-alpine-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>
  )
}

About

Sync reactive state across React and Alpine's `$store`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published