flowbite
flowbite copied to clipboard
Add attribute data-initialized=true to the component has been initialized
Is your feature request related to a problem? Please describe. I’m currently facing challenges with reinitializing Flowbite components dynamically in my project. When attempting to reinitialize components, it’s difficult to determine if a component has already been initialized, which leads to potential issues such as duplicate initializations or unnecessary reinitialization processes.
Describe the solution you'd like I would like Flowbite to add a data-initialized="true" attribute to each component after it has been initialized. This attribute would serve as a flag indicating that the component has already undergone the initialization process, making it easier to manage and control reinitialization in dynamic applications.
Describe alternatives you've considered An alternative solution could involve manually tracking the initialization state of each component within our application code. However, this approach is less efficient, more error-prone, and requires additional logic to maintain, especially as the number of components grows.
Additional context
Adding the data-initialized="true" attribute would greatly simplify the management of component states in dynamic environments where components are frequently added, removed, or updated. It would also enhance the flexibility of Flowbite in projects that require custom initialization logic. Here is a sample implementation:
Eg: initDropdowns
document .querySelectorAll('[data-dropdown-toggle]:not[ data-initialized="true"]')
It helps after Turbo stream renders the callback initFlowbite not re-initialized existing dropdown while user use it