Avoid no-shadow eslint error with mapDispatchToProps

前端 未结 6 1493
说谎
说谎 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:36

    Option 7...

    7. Use container components

    Why?

    It's a known pattern and you get the added benefit of decoupling your components from the redux store, making them easier to be reused.

    Why not?

    You now need two files per component.

    How?

    // FilterButton.jsx
    
    export default function FilterButton({ setFilter }) {
      return (
        
      );
    }
    
    // FilterButtonRedux.jsx
    
    import FilterButton from './FilterButton';
    import { setFilter } from '../actions/filter';
    
    export default connect(null, { setFilter })(FilterButton);
    

提交回复
热议问题