React-spring: Keyframes typescript usage

Created on 8 Jan 2019  路  5Comments  路  Source: pmndrs/react-spring

This could be a potential bug or I'm just missing something.

https://codesandbox.io/s/w7mjpk6455

The code:

import { animated, config, Keyframes, Trail, Transition } from "react-spring";

const LoadingWrapper = Keyframes.Trail(async (done: any) => {
  while (true) {
    await done({
      from: { background: "#191e23" },
      to: { background: "#303a44" }
    });
    await done({
      from: { background: "#303a44" },
      to: { background: "#191e23" }
    });
  }
});

function App() {
  return (
    <div className="App">
      <LoadingWrapper items={[1, 2, 3, 4]}>
        {(item: any) => (props: any) => (
          <div className="item" style={props}>
            Hi
          </div>
        )}
      </LoadingWrapper>
    </div>
  );
}

The error

/private/tmp/hmm/src/index.tsx
Type error: Type '{ children: (item: any) => (props: any) => Element; items: number[]; }' is not assignable to type 'IntrinsicAttributes & object'.
  Property 'items' does not exist on type 'IntrinsicAttributes & object'.  TS2322

    21 |   return (
    22 |     <div className="App">
  > 23 |       <LoadingWrapper items={[1, 2, 3, 4]}>
       |        ^
    24 |         {(item: any) => (props: any) => (
    25 |           <div className="item" style={props}>
    26 |             Hi

It runs fine on codesandbox but I can't compile it when you try to get a zip and try it locally.

bug render-props typescript

All 5 comments

All of TS is by contribution, could you look into the definitions and see if it's properly defined? And if not make a PR? I don't know TS good enough myself.

@radudascaluntt made the typings for the Keyframes class. Maybe he/she can explain this. I would also like to know what S and DS are meant to represent.

https://github.com/react-spring/react-spring/blob/45db119709bac7a70022485719d3d69a402b441a/types/renderprops-universal.d.ts#L272-L303

Closing this since Keyframes is about to be a legacy API.

Hi @aleclarson, looking at the demos react-spring looks fully awesome. With Keyframes becoming legacy what should we use instead for multi stage animations?

I think async to prop is the replacement.

to: async next => {
  await next({ foo: 1 }) // keyframe 1
  await next({ foo: 2 }) // keyframe 2
},
// ..or..
to: [{ foo: 1 }, { foo: 2 }],

Maybe useKeyframes would be a good addition, though. 馃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fortezhuo picture fortezhuo  路  3Comments

mkhoussid picture mkhoussid  路  3Comments

BertCh picture BertCh  路  3Comments

jmcruzmanalo picture jmcruzmanalo  路  4Comments

n1ru4l picture n1ru4l  路  3Comments