我得到一个状态值,即登录用户名,然后在我的页面上打印登录用户名。但是当我刷新页面时,状态值丢失了。
我正在使用 redux 创建状态值。
这是我的 action.js -
// Login - get user token
export const loginUser = userData => dispatch => {
axios
.post("http://localhost:5000/login", userData)
.then(res => {
// Save to localStorage
// Set token to localStorage
const { token } = res.data;
localStorage.setItem("usertoken", token);
// Set token to Auth header
setAuthToken(token);
// Decode token to get user data
const decoded = jwt_decode(token);
// Set current user
dispatch(setCurrentUser(decoded));
})
.catch(err => {
return err;
}
);
};
// Set logged …Run Code Online (Sandbox Code Playgroud) 大家好,我在设置状态后无法获取当前状态。我正在调用一个函数,我在其中传递该状态,但我总是在该函数中获得默认状态。这是我的状态-
const [currentValue , setCurrentValue] = useState(one[0]); // where one[0] is string "Test"
Run Code Online (Sandbox Code Playgroud)
这是我的 onchange 函数 -
const getTest = useCallback((newValue:string) => {
setCurrentValue({
label:newValue,
value:newValue
});
getCurrentValue(currentValue.value);
getSortOrder()
}, [])
Run Code Online (Sandbox Code Playgroud)
这是我的 getSortOrder 函数 -
const getSortOrder =() => {
console.log(currentValue);
}
Run Code Online (Sandbox Code Playgroud)
我没有在 getSortOrder 函数和 getCurrentValue 函数中获取更新的状态。但是,是的,如果我试图在渲染中控制台状态,那么它会向我显示更新的状态,但在功能中它不会更新。如何在两个函数中实现更新状态?
我正在将一个 onChange 事件作为道具传递给一个组件,但我收到了数据类型错误。
父组件 -
const onChangeStatus=(selectType:string , e:React.ChangeEvent<HTMLSelectElement>) => {
const { options } = e.target;
console.log(options)
}
<GlobalSearchAssignmentFilter
onChangeAssignmentStatus={onChangeStatus}
/>
Run Code Online (Sandbox Code Playgroud)
子组件 - 我已经定义了一个接口
interface A {
onChangeAssignmentStatus: (
selectType: string,
event:React.ChangeEvent<HTMLInputElement>
) => void;
}
Run Code Online (Sandbox Code Playgroud)
组件代码 - <选择多个原生 onChange={(event: React.ChangeEvent):void => onChangeAssignmentStatus(ASSIGNMENT_STATUS_PROPERTY , event) } inputProps={{ id: 'select-multiple-native', }} > {assignmentFilterData.assignmentDispositions. map((item: any) => ( {item.key} ))}
我正在从 Material UI 多选中导入 Select。当我将 onChangeAssignmentStatus 事件传递给子组件时出现错误。错误是——
Type '(selectType: string, e: React.ChangeEvent<HTMLSelectElement>) => void' is not assignable to type '(selectType: string, …Run Code Online (Sandbox Code Playgroud) 我想更改反应引导模式弹出窗口的背景颜色。
我的模态代码是 -
<Modal
show={this.state.show}
onHide={this.handleClose}
dialogClassName="modal-90w public-profile-modal-class"
size='lg'
aria-labelledby="example-custom-modal-styling-title"
>
Run Code Online (Sandbox Code Playgroud)
那么如何改变呢?
我试图在组件中设置背景图像,但它没有显示。这是我的家庭组件代码。
homecomponent.js
import React, { Component } from "react";
import logo from "./logo.png";
import CreateUser from "./create-user.component";
import { BrowserRouter as Switch, Route, Link } from "react-router-dom";
import "./custom.css";
export default class home extends Component {
render() {
return (
<div className="container-fluid homepage-bgimage"></div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
custom.css 文件代码 -
.homepage-bgimage {
background: url("http://abcd.com/static/media/slide.504dc6e6.jpg");
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)
我还在index.css 文件中将正文 html 添加到 100%,但背景图像仍然没有显示。
您好,我正在尝试在材质表上应用自定义 CSS,但它无法正常工作。我尝试在 Material UI 中使用 makeStyles 函数来做到这一点,但仍然不起作用。我想要排序箭头就在文本后面。现在排序箭头位于文本左侧。我还希望将向上箭头和向下箭头放在一起。我创建了一个函数 -
const useStylesTableSort = makeStyles({
root: {
flexDirection: "unset",
},
});
Run Code Online (Sandbox Code Playgroud)
这是我的材料表代码 -
<MaterialTable
className={{useStylesTableSort.root}}
style={{ flexDirection: "unset" }}
title=""
/>
Run Code Online (Sandbox Code Playgroud)
我想在材质表中使用 className 添加此函数,但材质表不支持 className。样式标签也不起作用。那么我怎样才能做到这一点呢?我想更改 MuiTableSortLabel 的根 css。任何帮助,将不胜感激。