No restricted globals

前端 未结 6 918
梦毁少年i
梦毁少年i 2021-01-30 03:58

I am using React and Redux to develop a webapp and when I started up my project I got this:

Line 13:  Unexpected use of \'location\'  no-restricted-globals

Sear         


        
6条回答
  •  你的背包
    2021-01-30 04:05

    Perhaps you could try passing location into the component as a prop. Below I use ...otherProps. This is the spread operator, and is valid but unneccessary if you passed in your props explicitly it's just there as a place holder for demonstration purposes. Also, research destructuring to understand where ({ location }) came from.

    import React from 'react';
    import withRouter from 'react-router-dom';
    
    const MyComponent = ({ location, ...otherProps }) => (whatever you want to render)
    
    
    export withRouter(MyComponent);
    

提交回复
热议问题