-
I have some Compose Multiplatform application code that connects to a SQLite database and puts that database into a CompisitionLocalProvider so that child components can access the database. Somewhere down the tree, I have a Component that should read from the database and get those results. I want to put that logic into the Component code so that I can query the database in the onCreate lifecycle callback, but I don't know how I can inject the database into the component, since there is no composable function inside the component code itself. Is there a way to instantiate a component with a composable function? Ideally in a ChildStack's childfactory function? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I think you do leverage Dependency Injection instead, pass the database class into your component via constructor. |
Beta Was this translation helpful? Give feedback.
-
I might be missing context, but this doesn't look like a good approach. You can create the database one of your component and pass it down to every child component, or have one single instance in the application, depending on the use case. |
Beta Was this translation helpful? Give feedback.
I might be missing context, but this doesn't look like a good approach. You can create the database one of your component and pass it down to every child component, or have one single instance in the application, depending on the use case.