I have parent component which showing records in table. When user click it redirect to child component with record Id passing in parameter using history push. This is all working fine but I need to pass an object of data in addition to parameter which I am not able to achieve and also what steps I need in child component to read this object?
Object Definition
export interface ISearchCriteriaForm{
startTime: string,
endTime: string,
liveTime?: string,
schedAction_Active: string,
siteId?: number,
scheduleId?: number
}
Parent Component
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
});
};
Child Component
const MyChildComponent = () =>{
const match = useRouteMatch("/eziTracker/eziStatus/:id/:hash");
const[eziStatusSearchCriteria, setEziStatusSearchCriteria] = useState<IEziStatusSearchCriteriaForm>();
useEffect(() =>{
},[]);
error
Expression expected. TS1109
88 | pathname: `${url}/${row.siteId}`,
89 | state: eziStatusSearchCriteria
> 90 | });
| ^
91 | };
92 |
93 | const setDefaultSearchCriteria = () =>{
{ // this is how I am trying to achieve ?? pathname:${url}/${row.siteId}, state: eziStatusSearchCriteria }state to variable and call it again in the history.push method as 2 statements. like, stackoverflow.com/questions/35821614/…