Skip to content
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

using autoAnimate with multiple parents in react in a single component #95

Open
Fawwaz-2009 opened this issue Oct 3, 2022 · 1 comment
Assignees

Comments

@Fawwaz-2009
Copy link

Hey Guys amazing library thanks so much for your contirbuation!. I wanted to ask is it currently possible to use auto animate with multiple parents in the same component. Something similar to the Vue below example from the docs.

I've been able to recreate the same example in react but not without extracting listItem and have it import it's own hook?

<script setup lang="ts">
import { ref } from "vue"
import { vAutoAnimate } from "../../../../src"
const faq = ref([
  {
    id: "why",
    question: "Why did you create it?",
    answer: `We needed a way `,
  },
  {
    id: "license",
    question: "Is it open source?",
    answer: `It sure is! AutoAnimate is MIT licensed,.`,
  },
  {
    id: "who",
    question: "Who made this?",
    answer: `AutoAnimate is a team effort 💪 . `,
  },
])
const current = ref(faq.value[0].id)
</script>

<template>
  <div class="example accordion-example">
    <ul class="accordion">
      <li class="accordion-item" v-for="q in faq" :key="q.id" v-auto-animate>
        <div
          class="question"
          @click="current = current === q.id ? false : q.id"
        >
          {{ q.question }}
        </div>
        <p class="answer" v-if="q.id === current" v-html="q.answer" />
      </li>
    </ul>
  </div>
</template>
@justin-schroeder
Copy link
Member

I think moving to using function refs instead of actual refs would solve this issue.

@justin-schroeder justin-schroeder self-assigned this Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants