S
S
Sergey Sokolov2018-11-12 19:27:25
Vue.js
Sergey Sokolov, 2018-11-12 19:27:25

Which is better: a standalone child component or passing props from the parent?

List component and sub-components of list items.
To display an element, you need to get the address of its image from the third service by an asynchronous request.
The list of elements is known immediately upon loading. Plus, elements in the list can be dynamically added by the user.
Who is responsible for uploading images?
I see two options:

  1. pass from top to bottom from the parent via props. When initializing the application with a known list. And when the list changes, request missing pictures from the service - the sub-components will be updated.
  2. the sub-component is completely autonomous, it was only passed the id of its object through props. The sub-component itself will request the address of the image: through some dispatcher / cache in the application or simply directly from the service.

The second one is more difficult, but seems "correct".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Mosin, 2018-11-13
@sergiks

IMHO option 1, so your child component will depend only on props, and not have any other dependencies, which will have a positive effect on testability and the possibility of reusing this component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question