这是我的无状态函数,它尝试返回元素数组:
function DeliveryPreference (props) {
return [
<h4>
Delivery Preference
</h4>,
<div className='yesNoCheckbox'>
<input type="radio" value={'tube'} onChange={props.onChange} id='tube' checked={props.value === 'tube'}/> <label htmlFor='tube'>Tube</label> <br/>
<input type="radio" value={'plate'} onChange={props.onChange} id='plate' checked={props.value === 'plate'}/> <label htmlFor='plate'>Plate</label><br/>
</div>
];
}
任何人都可以解释为什么我不能这样做,和/或提供解决方法吗?
非常感谢!
编辑: 这是错误的最小示例:
function App (props) {
return [
<div>1</div>,
<div>2</div>,
]
}
ReactDOM.render(
<App/>
, document.getElementById('root')
);
最佳答案
现在您可以返回一个数组,尝试一下 React 16 Beta
关于reactjs - 为什么 React 无状态函数不能返回数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34816032/