admin管理员组文章数量:1426118
I am trying to test a react search ponent with storybook, it gives a unboundStoryFn
error. The error says unboundStoryFn(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
I can't seem to find the problem.
import React from "react";
import PropTypes from "prop-types";
import "./SearchBox.css";
const STYLES = ["apolity", "skin", "cloud", "dark", "peacock"];
const fetchColor = (color) => {
var test = getComputedStyle(document.documentElement).getPropertyValue(
`--${color}`
);
return test;
};
const SearchBox = ({ style, type, onClick, color, className }) => {
style = STYLES.includes(style) ? style : STYLES[0];
color = STYLES.includes(color) ? fetchColor(color) : "#1e656d";
return (
<div>
<input
className={`searchbox ${style} ${className}`}
onClick={onClick}
type={type}
placeholder="Search"
></input>
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns=""
className={` search-icon `}
>
<circle
cx="10.5513"
cy="6.82051"
r="5.32051"
transform="rotate(90 10.5513 6.82051)"
stroke={color}
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M5.71802 10.9102L1.62828 14.9999"
stroke={color}
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
);
};
SearchBox.propTypes = {
style: PropTypes.string,
color: PropTypes.string,
};
SearchBox.defaultProps = {
style: "apolity",
color: "apolity",
};
export default SearchBox;
I am trying to test a react search ponent with storybook, it gives a unboundStoryFn
error. The error says unboundStoryFn(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
I can't seem to find the problem.
import React from "react";
import PropTypes from "prop-types";
import "./SearchBox.css";
const STYLES = ["apolity", "skin", "cloud", "dark", "peacock"];
const fetchColor = (color) => {
var test = getComputedStyle(document.documentElement).getPropertyValue(
`--${color}`
);
return test;
};
const SearchBox = ({ style, type, onClick, color, className }) => {
style = STYLES.includes(style) ? style : STYLES[0];
color = STYLES.includes(color) ? fetchColor(color) : "#1e656d";
return (
<div>
<input
className={`searchbox ${style} ${className}`}
onClick={onClick}
type={type}
placeholder="Search"
></input>
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3/2000/svg"
className={` search-icon `}
>
<circle
cx="10.5513"
cy="6.82051"
r="5.32051"
transform="rotate(90 10.5513 6.82051)"
stroke={color}
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M5.71802 10.9102L1.62828 14.9999"
stroke={color}
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
);
};
SearchBox.propTypes = {
style: PropTypes.string,
color: PropTypes.string,
};
SearchBox.defaultProps = {
style: "apolity",
color: "apolity",
};
export default SearchBox;
import React from 'react';
import SearchBox from './index';
export default {
title: 'Components/Search',
ponent: SearchBox,
argTypes: {
onClick: { action: 'clicked' },
style: {
control: {
type: 'select',
options: ['apolity', 'skin', 'cloud', 'dark', 'peacock'],
},
},
color: {
control: {
type: 'select',
options: ['apolity', 'skin', 'cloud', 'dark', 'peacock'],
},
},
},
};
const Template = (args) => {
<SearchBox {...args} />;
};
export const Type1 = Template.bind({});
Type1.args = {
color: 'apolity',
style: 'apolity',
};
File structure
Storybook error page
Share Improve this question edited Feb 10, 2021 at 3:28 Joundill 7,66513 gold badges38 silver badges53 bronze badges asked Feb 10, 2021 at 0:46 sudip-modisudip-modi 961 silver badge6 bronze badges1 Answer
Reset to default 3const Template = (args) => {
<SearchBox {...args} />;
};
should be
const Template = (args) => {
return <SearchBox {...args} />;
};
let me know if that fixes it. Whenever you get that error in react, it means you have forgotten a return statement somewhere. Or something that should be a ponent hasn't been initialized and given a value. But it's usually the first one.
本文标签:
版权声明:本文标题:javascript - unboundStoryFn(...): Nothing was returned from render. This usually means a return statement is missing. Or, to ren 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745418150a2657781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论