I have installed redux and react-redux using
npm install --save redux react-redux
I'm trying to use Redux arrow functions from App.js
like this:
import './App.css';
import MenuItems from './components/Navbar/MenuItems';
import ReactDOM from 'react-dom';
import React, { useState } from 'react';
import { createStore } from 'redux';
import {AddItemToCart, DeleteItemFromCart, Counter} from './cart.js';
let store = createStore(Counter);
store.subscribe(() => console.log(store.getState()));
<button onClick="store.dispatch(AddItemToCart())">Add to cart</button>
Here is my cart.js
:
import React from 'react';
import ReactDOM from 'react-dom';
export const AddItemToCart = () => {
return {
name: 'ADDITEMTOCART'
}
}
export const DeleteItemFromCart = () => {
return {
name: 'DELETEITEMFROMCART'
}
}
export const Counter = (state = 0, action) => {
switch (action.type) {
case 'ADDITEMTOCART':
return state + 1;
case 'DELETEITEMFROMCART':
return state - 1;
}
}
But that won't compile, I get error message:
Module not found: Can't resolve 'redux' in 'C:\Users\Admin\Documents\projects\Web_projects\myapp\myapp\src'
Any advise is highly appreciated.
Edit: I ran
npm install --save redux
now the error message changed to:
./src/App.js
Module not found: Recursion in resolving