Closed EvgenyiFedotov closed 4 years ago
import { createStore } from "effector"; import { createChange } from "patronum/change"; const $name = createStore(""); const changeName = createChange({ source: $name }); $name.watch(console.log); // => $name: "" changeName("Bob"); // => $name: "Bob"
import { createStore } from "effector"; import { createChange } from "patronum/change"; const $name = createStore(""); const changeName = createChange({ source: $name, prepend: (next, prev) => `${next}-${prev}`, }); $name.watch(console.log); // => $name: "" changeName("Bob"); changeName("Alise"); changeName("John"); // => $name: "John-Bob-Alise"
import { createStore } from "effector"; import { createChange } from "patronum/change"; import React from "react"; import { useStore } from "effector-react"; const $name = createStore(""); const changeName = createChange({ source: $name, prepend: (event) => event.currentTarget.value, }); const Name = () => { const name = useStore($name); return <input value={name} onChange={changeName} />; }; $name.watch(console.log); // => $name: "" // Typing in browser "Bob" // => $name: "Bob"
It is looks like a createApi, isn't it?
createApi
Yes, you right.
So I close the current issue because it is kind of createApi.
Example with source only
Example with prepend source
Example with prepend source (for react)