@dima89e

React Effector почему count не увеличивается и не передается в компоненте?

// App.jsx
import { counter, decrement, increment } from './init'

const App = () => {
  const count = counter.getState().count;
  console.log(count)

	return (
		<div>
			<h1>{count}</h1>
			<button onClick={increment}>+</button>
			<button onClick={decrement}>-</button>
		</div>
	)
}

export default App


// init.js
import { createStore, createEvent, combine } from 'effector'

const increment = createEvent()
const decrement = createEvent()

const $count = createStore(0)
	.on(increment, (state) => state + 1)
	.on(decrement, (state) => state - 1)

const counter = combine({
	count: $count,
})

export { counter, increment, decrement }
  • Вопрос задан
  • 50 просмотров
Решения вопроса 1
Mike_Ro
@Mike_Ro
Python, JS, WordPress, SEO, Bots, Adversting
// const count = counter.getState().count
const count = useStore(counter).count;
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Else Ростов-на-Дону
от 150 000 до 200 000 ₽
OWNR SOLUTIONS Нижний Новгород
от 150 000 до 250 000 ₽