Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component constructor props #5

Closed
dimooze opened this issue Dec 3, 2015 · 4 comments
Closed

component constructor props #5

dimooze opened this issue Dec 3, 2015 · 4 comments
Labels

Comments

@dimooze
Copy link

dimooze commented Dec 3, 2015

Hi !

First of all thanks for this work !

I have a problem when I use props in my constructor from a Component

export default class App extends Component {
  constructor(props) {
    super(props);
  }
}

props are always undefined. So i've found in the source that if i change createComponentFromVNode function like this

function createComponentFromVNode(vnode) {
    console.log('createComponentFromVNode', vnode);
    let props = getNodeProps(vnode);
    let component = componentRecycler.create(vnode.nodeName, props);

    //let props = getNodeProps(vnode);
    console.log('les props', props);
    setComponentProps(component, props, NO_RENDER);
    renderComponent(component, DOM_RENDER);

    // let node = component.base;
    //if (!node._component) {
    //  node._component = component;
    //  node._componentConstructor = vnode.nodeName;
    //}

    return component.base;
}

and the corresponding create function

create(ctor, props={}) {
  let list = componentRecycler.components[ctor.name];
  if (list && list.length) {
    for (let i=list.length; i--; ) {
      if (list[i].constructor===ctor) {
        return list.splice(i, 1)[0];
      }
    }
  }
  return new ctor(props);
}

It works fine, is that ok ?

Thanks :)

@developit
Copy link
Member

Hi @dimooze - yup, Preact was not passing props. I can get a PR in for that change if you'd like, was about to do another one.

If you don't mind my asking - what did you need props for within the constructor?

@developit developit added the bug label Dec 3, 2015
developit added a commit that referenced this issue Dec 3, 2015
Pass `props` through Component constructors (fixes #5)
@developit
Copy link
Member

@dimooze: Fix released in 2.5.0. Thanks.

@dimooze
Copy link
Author

dimooze commented Dec 4, 2015

Hey thanks for the merge !
I need it for react-redux Provider component :)

@developit
Copy link
Member

Awesome, I was hoping you would say that :P

marvinhagemeister pushed a commit that referenced this issue Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants