Avoid no-shadow eslint error with mapDispatchToProps

前端 未结 6 1477
说谎
说谎 2020-12-23 02:06

I have the following component that triggers a no-shadow ESlint error on the FilterButton props.



        
6条回答
  •  执念已碎
    2020-12-23 02:37

    With the new Hooks API added in v7.1.0, you can get rid of the variable and mapDispatchToProps altogether:

    import { useDispatch } from 'react-redux'
    import { setFilter } from '../actions/filter';
    
    function FilterButton() {
      const dispatch = useDispatch()
      return (
        
      );
    }
    
    export default FilterButton;
    

提交回复
热议问题