Hello, I am trying to use useNavigate from react r...
# javascript
r
Hello, I am trying to use useNavigate from react router and pass props through the component. Do you know how that maybe possible? I see the invoke function can take 2 args: "to" and "options" and I believe options is where I should be passing the props, but how is that done exactly?
t
You can use location state for this goal or search parameters (or both), depends on your case
Location state - option of
useNavigate
r
I'm currently using it like this: useNavigate.invoke("/path", _jso_*{state = state}*)
It redirects, but I get undefined error. The component also takes StateSetter as another prop, not sure how I would pass that down as well
t
jso { this.state = state }
Location state must be serializable
r
Yes, I have ensured that my data classes are serializable. I will try this out. Thank you!
t
It must be JS object or some primitive
Also you can use serialization in "dynamic object"
r
This is what I am currently doing: navigate.invoke("/payment-confirmation", jso { this.state = paymentInformationState })
val (paymentInformationState,paymentInformationStateSetter) = _useState_(PaymentInformation(cartSummary = cartSummaryState))
And the data class is serialized, but I am still getting undefined error
t
Data classes aren't serializable JS objects
r
Oh okay, doesn't jso {this.state = state} ensure that this is serialized though?
t
If state is serializable, then yes
👍 1