last day (15 days later) » 

4:43 PM
Hello
how is the problem :)?
<Link to={{
pathname: `/item/${item.id}`,
state: {id: item.id}
}}>
you should pass pathname to link with id and state
id is changing - so it can be "3729372938" or "3729372939" based on data
so in url will be specified link
and in state you pass data, which you wan't render in result
what type of error You getting ?
 
i am getting a undefined error on the id in Result.js
export default function Result({ id }) {
return (
<>
<div className="container">
<h5>
More information about that thing you just clicked on will be on this
page.
</h5>
<h1>id = {id.id}</h1>
</div>
</>
);
}
sorry
The Link looks like this
<Link
to={{
pathname: `/${id}`,
state: { id: result.id },
}}
className="waves-effect waves-light btn-small blue"
>
 
5:00 PM
ok
i try to fix it
 
But in the Result component, it doesnt look like anything is being passed in by bringing in {id} as a prop
 
i have solutions from one of my project
and i try to apply to your code
 
okay
 
meanwhile, you can try {id}, {id.props} or {props.id}
 
in the Result component?
 
5:02 PM
yes yes :)
 
no, all undefined
 
ok
need time
you can do something another, tea another code or relax
 
5:18 PM
ok
Destructurizing isn't neccessarry
Firsly in ResultItem you need your data in state
 
yeah it is in state
 
const ResultItem = () => {

const InitialState = {id: 5, title:'random'}
const [state, setState] = useState(InitialState)

return (
<div className="card grey lighten-4" style={{ padding: '1rem' }}>
<div>
<Link to={{
pathname: `/item/${state.id}`,
state: {title: state.title}
}}>
Read More
</Link>
</div>
</div>
);
}
if you have id in state
you can pass by pathname:

pathname: `/item/${state.id}`,
so in url You will have this id
 
yes i have the id in the URL
 
yeah so mine looks like this
 
5:25 PM
olk
const { match } = props;
let id = match.params;
if you add this on component
you can display id on screen by {id.id}
and depp in props, you have your state
 
hmm
 
and if you call
    <div>{props.location.state.title}</div>
 
Cannont read property of 'match' undefined error
 
you have one parameter of your state
ok
here you have parent component
and here have you your child component
and in routing you need to change to - <Route path="/item/:id" component={Result} />
probabbly it can't find match - because the routing doesn't change
questions? something doesn't work?
 
my state is undefined
 
5:32 PM
can you show code, please?
 
<Link
to={{
pathname: `/${id}`,
state: { id: result.id },
}}
className="waves-effect waves-light btn-small blue"
>
 
all comopnent
all component*
 
okay i have state
had to change route
?so in child component i do what
 
and in state you can send all paremeters:
title,
type,
id,
publisher,
volume,
issue,
page_number,
year_published,
state: {title: state.title, type: state.type, id: state.id}
etc.
in child
const Result = (props) => {

const { match } = props;
let id = match.params;

return (
<div>
<div>{id.id}</div>
<div>{props.location.state.title}</div>
</div>
)
}
you have everything in props.location.state
 
@Brock if you read this link:
https://tylermcginnis.com/react-router-pass-props-to-link/
you'll discover that you can pass {state} in with a link component, but you have to use props.location.state, you can't just do {id.id}
 
5:37 PM
thank you for time guys :) nice evening
 
i see,
thanks guys
 

last day (15 days later) »