API change proposal for useTransition
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);
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.
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 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.
Friendly reminder :) still interested in this API change?
@yuchi you want to make the PR? i think this is a good change - makes total sense to do it that way.
btw, some new ideas here: https://github.com/react-spring/react-spring/issues/425
This was implemented in v8.0.0