I am trying to undertake what should be a simple task of rendering a React component which handles some data. This requires a component container to be created, do actually handle the data part. Could someone comment if I doing this the correct way?:
I think the problem here is that you are doing dataHandle.find(). Subscription handles donāt give you access to the data directly, you need to get the data from the collection that the subscription publishes to. So if you have a collection called Lists, it could be Lists.find().
Also putting your props into state seems a bit āoverkillā as props are reactive too, so thereās no reason to use this.state.data when you could use this.props.data. It also makes it clearer (IMO) where the data is coming from that way too.
ok, so where is the name of the container defined? At present, I am calling <DataTableContainer /> in my List component, so Iām guessing I need a name for it (?)
Means that the container is exported as the default export. That means that when you import you simply import the file with any name you like, so long is that is how it is then referred to in that file:
import AnythingYouLike from '/containers/DataTableContainer.js'
render() {
return <AnythingYouLike />;
}
So, where I am stating that the container wraps DataTable (above), is there a way to be able to pass this value in, so that this container can be re-purposed and pass data to whichever presentation container I give it?
People usually donāt do this - imagine that your data container is just a very simple wrapper that injects data into a specific component. If you are doing heavy lifting in the container function and want to share that, Iād factor it out into a JavaScript module rather than trying to make the container work with multiple children.
So that both parts are easier to test, and itās clear which parts of your code depend on the global data and which donāt. You can also easily determine why your component is rerendering by logging from the container. If that idea doesnāt appeal to you, there are plenty of packages out there that just make Reactās render reactive.