question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inherit/Bind all props from parent

See original GitHub issue

Allow child component to auto inherit props from its parent.

<!-- ComponentA.vue -->
<template>
  <div>{{ hello }}</div>
</template>

<script> 
export default {
  props: {
    hello: String,
  },
};
</script>
<!-- ComponentB.vue -->
<template>
  <div>
    <component-a></component-a> World!
    <!-- or -->
    <component-a v-props></component-a> World!
  </div>
</template>

<script> 
import ComponentA from './ComponentA.vue';

export default {
  props: { ...ComponentA.props },
  components: { ComponentA },
};
</script>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
fnlctrlcommented, Oct 14, 2016

Hi, thanks for filling this issue. Inheriting everything is an anti-pattern, and had been removed from Vue long ago, so please declare the props specifically.

15reactions
saintplaycommented, Apr 30, 2018

I like to use a rendered function + functional component:

// ComponentB.js

import ComponentA from './ComponentA.vue';

export default {
  functional: true,
  components: {
    ComponentA
  },
  render (createElement, context) {
    return createElement(ComponentA, {
      props: {
        hello: 'My new Default', // You can even define
        language: 'pr', // default values.
        ...context.props // And then pass the remaining props
      },
      on: context.listeners
    })
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

VueJS pass all props to child component - Stack Overflow
Once you are satisfied with all the props, then you can use v-bind="$props" inside your child component to retrieve all the props.
Read more >
Pass all props to children in Vue - DEV Community ‍ ‍
You can do this for many levels of components, but remember that the props any child needs must be declared in all parents....
Read more >
How to Pass All Props to a Child Component in React - Medium
Being able to share all props from parent to child component in React lets you easily break your app up into small components....
Read more >
How to Pass Props Object from Child Component to Parent ...
Once state changes for a component which is passed as props down to the child component, then we see the app re-render again....
Read more >
Props | Vue.js
All props form a one-way-down binding between the child property and the parent one: when the parent property updates, it will flow down...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found