Reputation: 19
i'm creating store for adding data in redux store for that i used uuid() Function but it throws runtime Exception 'Uncaught TypeError: Illegal invocation'.
import {createStore,combineReducers} from 'redux';
import uuid from 'uuid';
//Add Expense
const addExpense = (
{description='',note='',amount=0, createdAt=0} ={}) =>({
type:'ADD_DETAIL',
expense: {
id:uuid(),
description,
note,
amount,
createdAt
}
})
//Expenses Reducers
const detailDefaultState = [];
const detailReducers = (state=detailDefaultState,action) =>{
switch(action.type){
case 'ADD_DETAIL':
return state.concat(action.expense)
default:
return state;
}
};
//Store Creation
const store = createStore(
combineReducers({
expenses:detailReducers,
})
);
store.subscribe(()=>{
console.log(store.getState());
})
store.dispatch(addExpense({description:'Rent',amount:100}));
if i remove uuid() function from code its run correct. version of uuid() is 3.2.0.
Upvotes: 0
Views: 713
Reputation: 1767
You are not importing uuid
correctly. You need to specify which type of uuid
you want to use, e.g.
// v4 - random uuid
import uuid from 'uuid/v4';
uuid(); // ⇨ will produce something like '45db52e1-f95c-4b5f-99a2-8b8d978c99b4'
You can read more about the types here: https://github.com/kelektiv/node-uuid.
Upvotes: 1