1

I want my page transition to happen conditionally based on screen size. I don't want the animation to happen on small screens. This is what I've written:

const mq = window.matchMedia( "(min-width: 600px)" )

  const transitions = useTransition(location, location => location.pathname, {
    from: {{mq ? transform: "translateX(100%)" : transform: "translateX(0)"}, position:'absolute', width: '100vw', opacity: 0},
    enter: {opacity: 1, width: '100vw', transform: "translateX(0)"},
    leave: {opacity: 0, transform: "translateX(-50%)"}
  })

I've tried different variations of this but it doesn't work.

jibaro
  • 103
  • 1
  • 12

1 Answers1

1

You were close. The property's key and value are technically expressions, so with that in mind you can have the ternary expression as the value. Having the whole thing as such is not valid syntax.

transform: mq? "translateX(100%)": "translateX(0)"
Jonathan Rosa
  • 992
  • 7
  • 22