Zaelot-Inc / use-reducer-logger

A very basic logger for the useReducer function in the React Hooks API.
https://www.npmjs.com/package/use-reducer-logger
MIT License
94 stars 16 forks source link

My event doesn't work after using module #2

Closed nos-nart closed 5 years ago

nos-nart commented 5 years ago
import logger from 'use-reducer-logger'
...
const tasksReducer = (state, action) => {
  let {task, id} = action
  switch (action.type) {
    ...
    case types.CHANGE_STATUS: {
      let idx = state.findIndex(ele => ele.id === id)
      state.splice(idx, 1, {id: state[idx].id, name: state[idx].name, completed: !state[idx].completed})
      localStorage.setItem('tasks', JSON.stringify(state))
      return state
    }
    ...
  }
}

const App = () => {
  const [tasks, dispatch] = React.useReducer(logger(tasksReducer), JSON.parse(localStorage.getItem('tasks')) || [])
  const [message, setMessage] = React.useState(messages.MSSG_SALUTE)

  const handleToggleStatus = id => {
     dispatch({
       id,
       type: types.CHANGE_STATUS
     })
     setMessage(messages.MSSG_CHANGE_STATUS)
   }

  return (
      <AppContainer>
           ...
          <ListTask tasks={tasks}
                   onToggleStatus={id => handleToggleStatus(id)}
      </AppContainer>
  )
}

I am new for react-hooks and trying to make an 'todo' app. I just got an issue .After importing 'use-reducer-logger' into my app the 'change_status' event doesn't work meanwhile the others event still works well (like add, remove, ...) Could anyone help me to understand why it doesn't work? Thanks

jefflombard commented 5 years ago

@nos-nart are you still having this issue? At a quick glance I'd check you're importing react. At this point I'm not so sure this is an issue with use-reducer-logger. If I am mistaken, please feel free to reopen this issue. I just ask that you give more context, i.e. what was happening previously, what changes were made to the code, and how did the behavior change. A link to a public repo would be even better!