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

Warning: CustomDisplayObject(...): A valid React element (or null) must be returned #72

Open
michalochman opened this issue Jan 27, 2017 · 3 comments
Assignees

Comments

@michalochman
Copy link
Contributor

michalochman commented Jan 27, 2017

I am trying to subclass a ReactPIXI.Sprite component, but every time I try to use it, I get the following error:

Warning: CustomDisplayObject(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

The minimal implementation of the component would be:

import ReactPIXI from 'react-pixi'

const SubSprite = ReactPIXI.CustomPIXIComponent({
  customDisplayObject: function(props) {
    console.log('this is not even called once');
    return new ReactPIXI.Sprite(props);
  },
  customDidAttach: function() {},
  customWillDetach: function() {},
  customApplyProps(oldProps, newProps) {
    this.applyDisplayObjectProps(oldProps, newProps);
  }
});

export default SubSprite

Then, when I try to use it like this:

render() {
    return React.createElement(SubSprite, { texture: PIXI.Texture.fromFrame('frame.png') }, null)
}

I get the above error.

What is the correct way to create custom components? A relevant section in the docs would be nice. I have also tried the exact code the SpinningSpriteComponent from the examples is using and I get the same error.

NB I am using:

  • react@15.4.2
  • pixi.js@4.3.4
  • react-pixi@0.9.5
@Izzimach Izzimach self-assigned this Jan 27, 2017
@Izzimach
Copy link
Owner

Well CustomPIXIComponent is not used much (if at all) and so hasn't been updated for more recent versions of React. With the changes to React transactions and context over the last few versions, the calls are probably broken. I'll try to check on it next week.

@michalochman
Copy link
Contributor Author

Wouldn't it be easier to just make createPIXIComponent method public API? The same goes for various Component Mixins that make up most of ReactPIXI components. Is there any reason for it not being exposed?

@Izzimach
Copy link
Owner

Izzimach commented Feb 9, 2017

The React internals churn a lot and if I exposed all that stuff things would break even more often than they do already, so I don't want to expose more stuff.

If you're wanting to make a bunch of custom PIXI components then you're probably better off forking and adding your elements in ReactPIXI.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants