【发布时间】:2021-04-09 08:20:49
【问题描述】:
我有显示表中记录的父组件。当用户单击它时,它会重定向到使用历史推送传入参数的记录 ID 的子组件。这一切都很好,但是除了我无法实现的参数之外,我还需要传递一个数据对象,以及我在子组件中需要哪些步骤来读取这个对象?
对象定义
export interface ISearchCriteriaForm{
startTime: string,
endTime: string,
liveTime?: string,
schedAction_Active: string,
siteId?: number,
scheduleId?: number
}
父组件
const MyComponentA = () => {
const [url] = useState("/eziTracker/eziStatus");
const[eziSearchCriteria, setEziSearchCriteria] = useState<ISearchCriteriaForm>();
//when row clicked on table
const selectedRow = (row: any) => {
//history.push(`${url}/${row.siteId}`); // this works
history.push({ // this is how I am trying to achieve ??
pathname: `${url}/${row.siteId}`,
state: eziStatusSearchCriteria
});
};
子组件
const MyChildComponent = () =>{
const match = useRouteMatch("/eziTracker/eziStatus/:id/:hash");
const[eziStatusSearchCriteria, setEziStatusSearchCriteria] = useState<IEziStatusSearchCriteriaForm>();
useEffect(() =>{
},[]);
错误
Expression expected. TS1109
88 | pathname: `${url}/${row.siteId}`,
89 | state: eziStatusSearchCriteria
> 90 | });
| ^
91 | };
92 |
93 | const setDefaultSearchCriteria = () =>{
【问题讨论】:
-
我认为这不是打字稿问题而不是 rect.js 错误中的问题。我认为您应该将
{ // this is how I am trying to achieve ?? pathname:${url}/${row.siteId}, state: eziStatusSearchCriteria }状态分配给变量,并在 history.push 方法中作为 2 个语句再次调用它。喜欢,stackoverflow.com/questions/35821614/… -
是否要使用查询参数过滤表数据?
-
你是对的,我已经改变了我为状态赋值的方式,它确实有效,参考我的回答