Skip to content

problem with jsx spread operator and props passed to children components #51

@sotaan

Description

@sotaan

Here is my code:

export const _isComponent = (tab) => tab.hasOwnProperty('component')
export const _askedForPassedProps = (tab) => tab.hasOwnProperty('props')

const TabContentWrapper = {
  functional: true,

  name: "TabContentWrapper",

  props: {
    // tabs: {
    //   type: Array,
    //   required: true
    // },
    //
    // activeTab: {
    //   type: Number,
    //   required: true
    // },



  },

  render (h, context) {
    const props = context.data.attrs,
      tabs = props.tabs,
      activeTab = props["active-tab"],
      contents = tabs.map( (_tab, index) => {
        const isComponent = _isComponent(_tab),
          isShown = index === activeTab

          let askedProps = _askedForPassedProps(_tab) && _tab.props,
            finalProps = {}

          if (askedProps) {
            _.each(askedProps, (prop) => finalProps[prop] = props[prop])
          }
          const data = { 'props': finalProps }
          debugger
        return isComponent ?
          <_tab.component v-show={isShown} {...data}></_tab.component> :
          <router-view v-show={isShown} name={_tab.name} {...finalProps}></router-view>
      })

    return (
      <div class="tab-content">
        {contents}
      </div>
    )
  }
}

export default TabContentWrapper

None of the techniques used to inject props works 😢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions