Realar shared state demonstration.
import React from "react";
import { prop, shared } from "realar";
class Hello {
@prop name = "" // Init immutable state
setName = (name: string) => {
this.name = name; // Update immutable state
}
};
const sharedHello = () => shared(Hello);
const Header = () => {
const { name } = sharedHello();
return (
<header>
Hello {name || "there"}!
</header>
)
};
const Main = () => {
const { name, setName } = sharedHello();
return (
<main>
<input
placeholder="Your name"
value={name}
onChange={(ev) => setName(ev.target.value)} />
</main>
)
};
export const App = () => (
<>
<Header />
<Main />
</>
);
Edit wrapped version on CodeSandbox.
Or try It on your computer 😊
git clone git@github.com:realar-project/hello.git
cd hello
npm i
npm run start
# Open http://localhost:1234 in your browser
Enjoy!