我正在尝试在 Codesandbox.io 上使用 Create React App,但我一直收到
TypeError _interopRequireDefault is not a function
import ReactDOM from "react-dom";
请告诉我如何解决这个问题,谢谢。
我有一个使用useState. 我现在想重构由应用程序管理的应用程序状态useReducer并继续使用localStorage.
我在弄清楚如何重构时遇到了麻烦,其中涉及到许多移动的部分。我如何重构内部的逻辑addToCartHandler以在ADD_TO_CART案例中使用?从那里,我相信我能够找出cartReducer. 谢谢你。
我正在使用 React 测试库测试我的组件是否成功地使用 Redux 呈现。我的实用程序组件无法通过 renderWithRedux 测试。这是我的 App 组件。
function App() {
return (
<>
<Router>
<NavBar />
<div className="container">
<Switch>
<Route exact path='/' component={Home}/>
<AuthRoute exact path='/login' component={Login} />
<AuthRoute exact path='/signup' component={Signup} />
<Route exact path='/users/:handle' component={UserProfile} />
<Route exact path='/users/:handle/post/:postId' component={UserProfile} />
</Switch>
</div>
</Router>
</>
);
Run Code Online (Sandbox Code Playgroud)
}
这是我的 AuthRoute 实用程序组件。
const AuthRoute = ({ component: Component, authenticated, ...rest }) => (
// if authenticated, redirect to homepage, otherwise redirect to signup or login
<Route
{...rest}
render={(props) …Run Code Online (Sandbox Code Playgroud) 在外面柜台在很多的YouTube视频教程看到的例子,什么是实用/现实世界中使用案例useMemo和useCallback?
另外,我只看到了钩子的输入焦点示例useRef。
请分享您为这些钩子找到的其他用例。
这是一个类组件,我想使用它重构为功能组件useReducer
export default class FootballMatchesData extends Component {
constructor(props) {
super(props);
this.state = {
selectedYear: null,
matchData: [],
firstCall: false
};
}
chooseYear = (year) => (e) => {
this.setState({
selectedYear: year
})
axios.get(`https://website?property=${year}`)
.then(res => {
this.setState({ matchData: res.data, firstCall: true })
})
}
render() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在定义我的减速器的“CHOOSE_YEAR”情况。我将如何定义这种情况,以便:
selectedYearhttps://website?property=${year},然后填充matchDatafirstCall这是我当前的重构。https://codesandbox.io/s/gracious-pare-um66h?file=/src/FootballMatches.js