Coder Social home page Coder Social logo

React hooks about lax.js HOT 11 CLOSED

AndrewThian avatar AndrewThian commented on May 18, 2024
React hooks

from lax.js.

Comments (11)

alexfoxy avatar alexfoxy commented on May 18, 2024

Hey! Glad you're enjoying it :)

I didn't write the react hooks lib but I'll gladly take a look if you can provide an example!

from lax.js.

AndrewThian avatar AndrewThian commented on May 18, 2024

Ahhh, hooks are a native react implementation! Lemme double check if it's also breaking using React classes and I'll report back ASAP :)

If not then, I'll leave an example here for how to replicate the scenario!

from lax.js.

alexfoxy avatar alexfoxy commented on May 18, 2024

How did u get on?

from lax.js.

AndrewThian avatar AndrewThian commented on May 18, 2024

hey! so sorry, got caught up with work work. But here are some findings!

React version 16.8.6

Findings:

  1. Class implementation of lax.js works [obviously].
  2. If you define lax.setup in a class constructor on the root element, using hooks to add lax.addElement also works.
  3. However, if you use useEffect hook to initialize lax.setup it fails to update the subscribed element

I'm double checking on a code sandbox to see if it's consistent too! One moment

Edit:
Here's a react sandbox:
https://codesandbox.io/embed/nryzvz71wp

Basically, there are two types of setups:

  1. [Fails] using a function and react hooks useEffect to setup lax
  2. [Passes] using a class constructor and setup lax

I'll be diving deeper later but this is all I have for now!

from lax.js.

arthurdenner avatar arthurdenner commented on May 18, 2024

@AndrewThian, if you move the lax.setup call to outside of the useEffect hook, it works as expected, but I'm not sure if that's the right solution because as you said, it worked properly with v1.1.0.

@alexfoxy, a pull request was opened on my library, use-lax, to move the call to outside of the hook, but I think the more problem is on lax itself.

from lax.js.

alexfoxy avatar alexfoxy commented on May 18, 2024

lax.setup() should be called before anything else as it sets it's elements equal to []. I debugged your example and useEffect() in bubble.js gets called before useEffect() in App.js.

You should only call lax.setup() in App constructor.

from lax.js.

arthurdenner avatar arthurdenner commented on May 18, 2024

@alexfoxy, nothing changed in lax within 1.1.x and 1.2.x? Because it works properly with previous versions using lax.setup inside the hook (after the component mounts).

from lax.js.

arthurdenner avatar arthurdenner commented on May 18, 2024

Check out this sandbox with [email protected] and then upgrade it to the 1.2.0.

from lax.js.

alexfoxy avatar alexfoxy commented on May 18, 2024

It is because in previous versions lax would look for components with attribute names to populate elements e.g. data-lax-preset="fadeIn" so it was finding the bubble element when lax.setup() was called. In v1.2 you need to add class='lax' to any elements that you want to be automatically animated by lax, so you can fix your example with className="bubble lax", however it makes more sense to do what I said and call lax.setup() asap.

from lax.js.

AndrewThian avatar AndrewThian commented on May 18, 2024

ahhhhhh, totally my bad. Didn't read the README well enough! Thanks so much for explaining @alexfoxy really helped out a lot. You're right, I think just shifting the lax.setup outside of the useEffect hook would mean lax is initialized with the creation of the function just like the class constructor.

May I suggest a update in documentation for those using React hooks and migrating from 1.1.x to 1.2.x? :) Thanks again!

from lax.js.

arthurdenner avatar arthurdenner commented on May 18, 2024

It is because in previous versions lax would look for components with attribute names to populate elements e.g. data-lax-preset="fadeIn" so it was finding the bubble element when lax.setup() was called. In v1.2 you need to add class='lax' to any elements that you want to be automatically animated by lax, so you can fix your example with className="bubble lax", however it makes more sense to do what I said and call lax.setup() asap.

I see, thanks for the explanation.

from lax.js.

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.