Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Is using Renderless Component a good way for common functionality?

I have two Vue components with the same method (copy-paste). I would like to avoid that duplication and I am looking into the best way to do that. Note that the method uses mapped state and actions from Vuex.

I ended up creating a Renderless Component with the following outline:

<script>

import { mapState, mapActions } from 'vuex';

export default {

  name: "CommonHandler",

  render: () => null,

  props: {
    prop: {
      type: User,
      required: true,
    },
  },

  methods: {

    ...mapActions({
      mapAction1: "mappings/mapAction",
    }),

    commonMethod() {
      /*Use computed variables and actions...*/
    },
  },

  computed: {
    ...mapState({
      users: state => state.users,
    }),
    currentUser() {
      return this.users.find( element => element.id === this.prop.id );
    },
  },
};
</script>

Then, in those two components I instantiate the component above, add a ref to it, and just call the common method like this:

this.$refs.commonComponent.commonMethod();

Is this a good way to solve this problem?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda