This looks like an Dependency Injection (or the Container) pattern where one would inject properties (props) so it'd make not only the Thing more customizable and dumb but also easily testable 🙂
Yes, this is very close to what Dan Abramov told about. But not quite DI, as you'd need to introduce another layer, where you can explicitly pass the ThingView source. Right now it's coupled with its container.
And yes again, this makes this approach very testable, as you can do UI testing with mocked data and don't worry about any logic behind it.
Thanks for the explanation Tomek 🙏
I can see how this pattern can work to even extract the component to publish on NPM to be used separately altogether 😮
This looks like an Dependency Injection (or the Container) pattern where one would inject properties (
props
) so it'd make not only theThing
more customizable and dumb but also easily testable 🙂Did I understand it correctly? 😅
Hello Sung,
Yes, this is very close to what Dan Abramov told about. But not quite DI, as you'd need to introduce another layer, where you can explicitly pass the
ThingView
source. Right now it's coupled with its container.And yes again, this makes this approach very testable, as you can do UI testing with mocked data and don't worry about any logic behind it.
Thanks for the explanation Tomek 🙏
I can see how this pattern can work to even extract the component to publish on NPM to be used separately altogether 😮
Yes, like I said earlier, you can easily create an extra layer that will inject the view rather than use it implicitly via internal import.