react-spring icon indicating copy to clipboard operation
react-spring copied to clipboard

API change proposal for useTransition

Open yuchi opened this issue 7 years ago • 7 comments

Description

Since configuration for a transition is usually static or a static composition of functions, it makes sense to define it outside of the component body:

const config = {
  trail: 100,
  from: { opacity: 0 },
  enter: { opacity: 1 },
  leave: { opacity: 0 }
};

const keys = item => item.id;

function MyAnimation({ items }) {
  const transitions = useTransition({ items, keys, ...config });
  // ....
}

The current approach of having a single configuration argument makes this slightly less usefull since you need to spread that static configuration over the object that includes items and keys too.

Proposal

I propose to change the API to this:

useTransition(items, keys, config);

This reduce the need for the creation of a pretty useless object at render time.

Additional note

This makes the API more coherent with useTrail:

useTrail(items.length, config);
useTransitions(items, keys, config);

yuchi avatar Dec 20 '18 22:12 yuchi

Makes sense! The only thing i don't like is that keys is optional right now, here it would take a fixed spot with this approach. On the other hand, maybe we're better off enforcing keys, making users think about this, because default keys (props => props) can fail.

drcmda avatar Dec 21 '18 08:12 drcmda

Willing to accept a PR for this or you want to do it yourself? I'll just wait for your confirmation on the second keys argument.

yuchi avatar Dec 25 '18 23:12 yuchi

@yuchi I think it's a good idea. feel free to create a PR for this of course. as this is going to be a breaking change. maybe wait for @drcmda to get back from the holidays.

ruggedy avatar Dec 26 '18 00:12 ruggedy

Friendly reminder :) still interested in this API change?

yuchi avatar Jan 07 '19 20:01 yuchi

@yuchi you want to make the PR? i think this is a good change - makes total sense to do it that way.

drcmda avatar Jan 08 '19 11:01 drcmda

btw, some new ideas here: https://github.com/react-spring/react-spring/issues/425

drcmda avatar Jan 09 '19 11:01 drcmda

This was implemented in v8.0.0

aleclarson avatar Apr 01 '19 01:04 aleclarson