https://kotlinlang.org logo
#javascript
Title
# javascript
r

Richard Ulysse

03/06/2024, 4:49 PM
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

turansky

03/06/2024, 6:43 PM
You can use location state for this goal or search parameters (or both), depends on your case
Location state - option of
useNavigate
r

Richard Ulysse

03/06/2024, 6:55 PM
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

turansky

03/06/2024, 7:09 PM
jso { this.state = state }
Location state must be serializable
r

Richard Ulysse

03/06/2024, 7:11 PM
Yes, I have ensured that my data classes are serializable. I will try this out. Thank you!
t

turansky

03/06/2024, 7:13 PM
It must be JS object or some primitive
Also you can use serialization in "dynamic object"
r

Richard Ulysse

03/06/2024, 7:16 PM
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

turansky

03/06/2024, 7:19 PM
Data classes aren't serializable JS objects
r

Richard Ulysse

03/06/2024, 7:22 PM
Oh okay, doesn't jso {this.state = state} ensure that this is serialized though?
t

turansky

03/06/2024, 7:29 PM
If state is serializable, then yes
👍 1