Coder Social home page Coder Social logo

Comments (8)

drcmda avatar drcmda commented on June 18, 2024

What's reacts error when you merge? I use mergerefs all the time and never saw a warning, must be something else imo

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

@drcmda here is the error I get:

Warning: [object Object]: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop.

it happens when I try to merge refs[i] and el.props.ref

here's a demo of this case: https://codesandbox.io/s/trying-to-get-effect-ref-9zzl1?file=/src/App.js

from react-postprocessing.

drcmda avatar drcmda commented on June 18, 2024

try clone in that case https://reactjs.org/docs/react-api.html#cloneelement

Clone and return a new React element using element as the starting point. The resulting element will have the original element’s props with the new props merged in shallowly. New children will replace existing children. key and ref from the original element will be preserved.

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

@drcmda maybe I'm using this wrong but it's still { current: undefined } :/

I used this StackOverflow answer so the code looks like this:

https://github.com/react-spring/react-postprocessing/blob/ab4030d2537d844e89e1e367c440aa947d509f8e/src/EffectComposer.tsx#L65-L71

and in demo it looks like this:

https://github.com/react-spring/react-postprocessing/blob/3a89610a586326e5b78d7fb325053efd49326788/examples/pages/outline.jsx#L10-L40

Even if it is said that cloneElement preserves refs, looks like here it gets overidden anyway.

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

I've set up a codesandbox to debug the composer easier, but still no result yet :/

https://codesandbox.io/s/boring-noether-7uli0?file=/src/components/EffectComposer.tsx

it's being undefined

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

@drcmda so I talked to some guys in a React chat on Telegram and came to a conclusion that the whole EffectComposer implementation is wrong. We cannot merge refs, neither we can't assign them because they are occupied already even with cloneElement

I think that it's worth trying to implement it with children again, but there is a problem with state.... we can't have state if don't render children but just map through them and send to EffectPass

any ideas?

should I keep the existing implementation and keep trying to make it work (but I honestly don't know what else to try)

or it's better to completely rewrite the composer and effects?

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

I think I got something: https://codesandbox.io/s/intelligent-dhawan-yo4lj?file=/src/App.tsx

might be some unexpected problems though

from react-postprocessing.

talentlessguy avatar talentlessguy commented on June 18, 2024

Fixed in last version, works nicely!

from react-postprocessing.

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.