immer is a very good library, but when combined with the create-react-app, it warning: Expected a default case default-case, is there a good solution? Of course, if you add a blank default-case can solve this problem.
function reducer(state = {}, action) {
return produce(state, draft => {
switch (action.type) {
case ACTION_A:
break
case ACTION_B:
break
// default:
}
})
}
Nope, (I think it is a stupid rule in the first place :). Static type
checkers can perfectly assert whether a default cause can happen or not.). Adding default is the simplest solution here.
For this craco (https://github.com/sharegate/craco) may be an "easy" solution. I just updated my package.json like this:
"scripts": {
- "start": "react-scripts start",
+ "start": "craco start",
- "build": "react-scripts build",
+ "build": "craco build",
- "test": "react-scripts test",
+ "test": "craco test",
- "eject": "react-scripts eject",
+ "eject": "craco eject",
And used this craco.config.js:
module.exports = {
eslint: {
enable: true,
mode: 'extends',
configure: {
rules: {
'default-case': 0
}
},
},
};
This seems to work pretty well with create-react-app (https://github.com/facebook/create-react-app).
Most helpful comment
Nope, (I think it is a stupid rule in the first place :). Static type
checkers can perfectly assert whether a default cause can happen or not.). Adding
defaultis the simplest solution here.