Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!