import React, {useReducer} from 'react'
import _ from 'lodash'
import { v4 as uuid } from 'uuid';

function reducer(state, action){
    switch (action.type){
        case 'add':
            if (state.guess.length <= 3){
                return {guess: _.concat(state.guess, {...action.payload, id: uuid()})}};
        case 'remove':
            return {guess: _.filter(state.guess, el => (el.id !== action.payload.id))};
        case 'reset':
            return {guess: []};
        default:
            throw new Error();
    }
}

//in component function:
let [state,dispatch] = useReducer(reducer,{guess: []}),