-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make SpringRef instances callable to avoid breaking change #1359 #1387
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9a39ae2:
|
I don't think this has the intended effect. A few issues stand out:
|
…into fix/v9-fixes
…into fix/v9-fixes
@a-type sorry just seen your comment now, we were discussing internally and @joshuaellis made me realize the existence of // v9.0.0-rc3
const [springs, set] = useSpring(() => ({ x: 0 }))
set({ x: 3 }) // this animates to 3
// v9.0.0
const [springs, set] = useSpring(() => ({ x: 0 }))
set({ x: 3 }) // this doesn't work
// v9.0.0
const [springs, { set }] = useSpring(() => ({ x: 0 }))
set({ x: 3 }) // this doesn't work because this.current is undefined
// v9.0.0
const [springs, api] = useSpring(() => ({ x: 0 }))
api.set({ x: 3 }) // this does work but doesn't animate
api.start({ x: 3 }) // this does work and animates
// v9.0.0 PR #1387
const [springs, api] = useSpring(() => ({ x: 0 }))
api({ x: 3 }) // this animates to 3 and avoids breaking change So at this point I think we're good, since we're fixing breaking changes. |
@dbismut Yeah the new changes look better - although I don't think |
@a-type actually it seems like |
@dbismut oh nice, it wasn't working for some reason when I was testing my sandbox with the newest commit. Perhaps I did something wrong. |
@dbismut I've added a utility function - |
I am! Initially I thought I would keep this PR open and push all fixes based on potential bugs I would find in the demo sandboxes, so I don't know if you want to merge on master now or wait until I complete the sandboxes? |
Let's wait till we've merged those other changes, but I would like to merge this separately just so if we need to revert for whatever reason, its straight forward to do so, so maybe we could merge into master post merging the others? |
Makes sense! We can change the target to master later on. Let's do the demos first then! |
great job! glad you already found a solution. is there a workaround until this one is merged? |
@mmintel the workaround is actually what we recommend using as we're deprecating calling the ref directly. const [springs, api] = useSpring(() => ({x: 0}))
api.start({x: 3}) |
I has a few questions about this, this works for me in relation to useSpring, but I've tried this with a wrapped useTrail hook and it is complaining. When trying to call the spring ref it replies with "This expression is not callable. Type '{}' has no call signatures.ts(2349)". The sandbox still seems to work but in my project the settings are setup to prevent it from building with typescript errors like this: https://codesandbox.io/s/white-sunset-26qsi?file=/src/App.tsx |
To be honest, i'm not encouraging the use of this. So unless it's a real blocker like #1423 I don't think we're going to look into issues with it. You should just call |
Ok that's fair enough, I've copied and pasted my spring wrapper into the above sandbox and it shows no typescript errors: https://codesandbox.io/s/white-sunset-26qsi?file=/src/App.tsx But inside vscode there seems to be some sort of an issue maybe with the typings in the library that is flagged an error? The error specifically being: |
This is our example of |
Hmmm that's strange, it seems to only be an issue with that particular line, I've gone through and updated my dependencies including typescript to match the sandbox but was still receiving the error. I put in a @ts-ignore flag and in the background react-spring seems to work as expected. It must be an issue with the typescript setup somewhere along the line. |
Fixes #1359
Other changes
Fixes PickAnimated type eaf473f
Before - tries to union all props, including arrayed props, resulting in unknown types:
After - infer SpringValue types only from the
from
prop when it exists:This — I think — should be fine considering that the
from
prop is mandatory.