Coder Social home page Coder Social logo

Comments (8)

steven-lury avatar steven-lury commented on June 10, 2024 1

@reinink onSuccess or other eventListener doesn't work in my project but when I use then it works. Do you have any idea

from inertia.

reinink avatar reinink commented on June 10, 2024

@sebastiandedeyne Is this still an issue in React, or have you found a sensible workaround here?

I ask because we've deprecated the visit promises in favour of the new event callbacks. However, if this problem still exists, we could potentially return the page object to the onSuccess() callback.

from inertia.

sebastiandedeyne avatar sebastiandedeyne commented on June 10, 2024

This is still an issue. I think the onSuccess callback is a good solution to this.

Maybe the new event system could provide a workaround, but I think that'd be a weird place to do that.

from inertia.

reinink avatar reinink commented on June 10, 2024

Yeah, okay cool. I think we can make this happen.

Next question then, should the onSuccess() callback get the whole page object (url, version, props), or just the props?

Option 1 (entire page object)

return onSuccess(this.page)

Option 2 (props only)

return onSuccess(this.page.props)

Option 3 (treat props as the page, but include the url and version)

return onSuccess({
  page: this.page.props,
  url: this.page.url,
  version: this.page.version,
})

So, this is tricky, because right now in the Vue.js adapter, $page is actually just the props. We made this decision to avoid having to do $page.props every time. However, there are times where having access to the URL would be nice ($page.url), so I've considered adding a $url property as well.

Either way...do we need to be consistent here?

from inertia.

reinink avatar reinink commented on June 10, 2024

To be honest, I kind of hate that we ever scoped page.props to $page in Vue.js. Yes, it's a nice convenience, but in reality I think it confuses what the "page" object is in Inertia.js. I kind of feel like we should move toward not doing this, and MAYBE even consider making this a change in the Vue.js adapter.

from inertia.

reinink avatar reinink commented on June 10, 2024

Okay, onSuccess() now receives the page object.

Considering this issue resolves. 🙌

from inertia.

claudiodekker avatar claudiodekker commented on June 10, 2024

@steven-lury Probably you're using an outdated version of Inertia, as the onSuccess and other event listeners were introduced in @inertiajs/inertia version 0.3.0: https://github.com/inertiajs/inertia/releases/tag/v0.3.0

Could you try updating both the @inertiajs/inertia package in your application, as well as your stack-specific (react, vue or svelte) Inertia adapter? I believe that should solve your issue.

from inertia.

grantholle avatar grantholle commented on June 10, 2024

I haven't found the reasoning on deprecating promises. Could someone elaborate for me?

Edit: Moving to discussions, sorry for the spam

from inertia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.