Closed alexnofoget closed 5 years ago
Are you using react hooks somewhere in your code?
Are you using react hooks somewhere in your code?
No, but this error doesn`t occure if I use this component without storybook
OK, I'll take a look at your repo
Investigating...
Seems the problem is with how addon-info (storybook) + withStyles (@material-ui/core/styles) interop.
This line seems to cause react to think it's not rendering a functional component, which is what hooks needs to operate.
extract(innerChildren.type.render(innerChildren.props));
Found a fix, opened a PR
Hi @ndelangen , thanks for looking into this. I have the same issue here. Can we expect the PR to be merged/released soon?
Thanks
@ndelangen I'm having the same issue. Do you know when this PR will be merged? Is there any work around until then? maybe lowering the react version? I tried, but didn't work.
Same here after upgrade to material-ui V4 everything is broken.
I just ran into this as well.
Seems the workaround for the time being is to stop using withInfo decorator until it's fixed. I think I got a few other components working by removing withStyles from the tree but can't really do that everywhere at this time so I just commented out the withInfo add decorator line in my config and am going forward with that for now.
I am not sure this is the best place to ask this question, but anyway, can I use makeStyles
function inside class ? I got an Invalid hook call
. Is there any possible way to use the function makeStyles
?
Yowza!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-rc.3 containing PR #6859 that references this issue. Upgrade today to try it out!
Because it's a pre-release you can find it on the @next
NPM tag.
Closing this issue. Please re-open if you think there's still more to do.
I tried it and I still get the same error, my devDeps look like this:
"devDependencies": {
"@babel/core": "^7.4.5",
"@storybook/addon-actions": "^5.1.0-rc.3",
"@storybook/addon-info": "^5.1.0-rc.3",
"@storybook/addon-links": "^5.1.0-rc.3",
"@storybook/addons": "^5.1.0-rc.3",
"@storybook/react": "^5.1.0-rc.3",
"@types/jest": "24.0.13",
"@types/storybook__addon-actions": "^3.4.2",
"@types/storybook__react": "^4.0.1",
"awesome-typescript-loader": "^5.2.1",
"react-docgen-typescript-loader": "^3.1.0",
"babel-loader": "8.0.5",
"jest": "24.7.1"
}
@shawnmclean @DwayneSamuels could you help me reproduce?
a list of dependencies isn't enough for me to be able to reproduce unfortunately.
I was able to reproduce before using @alexnofoget repo, before, but the fact you're still experiencing an issue, suggest your issue might have a different cause.
I just tried the new code with the 5.1.1 release and I am no longer seeing the error, so this is fixed for us now.
I'm not sure that my problem is same as this. But I see similar error then I'm trying to run tests in cypress using storybook v. 5.3.9. But there is no errors then I run storybook alone, without tests. So this is only one issue that seems like my problem I could find. Does anyone here know anything about it?
@XanderSpecter share more about your setup (config + a failing test?) and somebody can help?
@shilman I didn't make configs in that project. So, I don't know, that configs I need to share :(
I have a story for component:
import React from 'react';
import TextField from '@material-ui/core/TextField';
document.TextField = TextField;
export default { title: 'Основные компоненты|Текстовые поля/TextField', component: TextField };
export const emptyStory = () => <div className="text-field-empty-story-root"></div>;
emptyStory.story = {
name: 'empty',
};
Now I'm importing TextField from metarial without my wrapper because I'm trying to solwe this problem thiwhout my code.
Also I have a spec for cypress that connects to storybook using this empty story and trying to render component and run tests:
import React from 'react';
import ReactDOM from 'react-dom';
const rootToMountSelector = '.text-field-empty-story-root';
const selectors = {
input: '.MuiInputBase-input',
};
before(() => {
const testURI = 'localhost:9004/iframe.html?id=основные-компоненты-текстовые-поля-textfield--empty-story';
cy.visit(encodeURI(testURI));
cy.get(rootToMountSelector);
});
afterEach(() => {
cy.document()
.then((doc) => {
ReactDOM.unmountComponentAtNode(doc.querySelector(rootToMountSelector));
});
});
it('При отрисовке будет содержать элемент input.', () => {
cy.document().then((doc) => {
ReactDOM.render(
<doc.TextField
// doc={doc}
/>,
doc.querySelector(rootToMountSelector),
);
});
cy
.get(selectors.input)
.should('be.exist')
.should('be.visible');
});
If you need more information please say what configs I need to share.
And sorry about my bad English :)
Hmm, sorry I'm not sure. Maybe somebody else knows?
That scheme of tests works with another components that not using material-ui. But with material test runs, sucsessfully connects to storybook, try to render and throw same error as in topic of this issue
I have an error with storybook and react hooks
Example with the same error here https://github.com/alexnofoget/storybook-issue