我正在创建一个React组件,其中包括一个复选框。我希望它来回切换(打开和关闭),并将状态保存在本地存储中,因此如果我转到另一个页面,切换将被设置为以前的状态。
注意:我没有使用React 16,也不能使用状态挂钩。
我创建了组件并添加了ComponentDidMount和ComponentDidUpdate函数,如下所示。
import * as React from "react";
import { Checkbox } from 'semantic-ui-react'
type Props = {
label : string
}
type
我目前正在做一个使用react,redux和firebase的next.js项目。当用户进入一个需要授权的页面时,如果他们没有通过身份验证,我会使用以下代码来重定向他们。 import React from 'react';
import Router from 'next/router';
import { firebase } from '../../firebase';
import * as routes from '../../constants/routes';
const withAuthorization =
我在我的webapp中有react-redux和react-router,而我试图在保持redux状态的同时更改路由。我尝试了所有这些,它们都删除了redux状态:
props.history.push({ pathname: `/my-path`}); // did this using withRouter and useHistory
<Link to={'/my-path'} />cool link</Link>
我做错了什么?我怎样才能保持状态?(我不能将其保留在localStorage中的原因是,当用户关闭该页面时,数据应该会消失)