Multiple Instances of Same Block On 1 Page - How To Have Unique State For Each One #60440
Replies: 2 comments 7 replies
-
I ran into the same with my gallery slider. The issue is that you need to use context for any instance-level variable. Have a look at my implementation here - https://github.com/ryanwelcher/iapi-gallery-slider |
Beta Was this translation helpful? Give feedback.
-
@ryanwelcher I had a quick question for you. I'm not actually making the following argument; I'm trying to work through my understanding of the API and wanting someone to correct my understanding. What is the point of using getters to return values into state? Why not just work 100% with context directly? What advantage is state offering you? Doesn't the DOM update reactively to context changes just as much as it does to state changes? Wouldn't it be easier to just access and mutate context instead of state? Again, I'm not actually making those arguments, I'm trying to correct my understanding. Thank you so much! |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm loving this new API! Thank you to everyone who has worked tirelessly on this!
I'm using this in my render.php:
wp_interactivity_state('create-block', myPhpArrayDataHere)
And then in my view.js I have this:
const { state } = store("create-block", {}
This was working wonderfully for me until I added multiple instances of the same block type on 1 WP post/page. All instances use the state from the final block instance on the page.
I feel like I'm missing something super obvious, but I've tried every Google + cmd+F search I can think of. Anyone have any tips on how to have each state be unique for each instance of the block?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions