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

cannot set VirtualList item from React.createElement(com, props) with props, got undefined #15993

Open
simline opened this issue Jun 27, 2024 · 0 comments
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@simline
Copy link

simline commented Jun 27, 2024

相关平台

H5

浏览器版本: chrome 126.0.6478.126
使用框架: React

复现步骤

function buildData(offset = 0) {
    return Array(20)
        .fill(0)
        .map((_, i) => i   offset)
}

function DefItem (props) {
    return (
        <View id={props.id} className={props.index % 2 ? 'ListItemOdd' : 'ListItemEven'}>
            Row {props.index} : {props.data[props.index]}
        </View>
    )
}
const itemData = buildData()
const dataLen = itemData.length

...
		{	com		: 'list',
			props	: {
                itemCount		: dataLen,
				itemData		: itemData,
				item			: DefItem,
				itemSize		: 100,
				unlimitedSize	: true,
			},
			request : { url:'prds', method:'GET' },
		...
}

...

React.createElement(
		Component,
		props,
		children && children.map(child => createElementRecursive(child))
	);

But use jsx with DefItem works fine.

期望结果

same as the doc https://docs.taro.zone/docs/next/virtual-list/

      <VirtualList
        height={800} /* 列表的高度 */
        width="100%" /* 列表的宽度 */
        item={Row} /* 列表单项组件,这里只能传入一个组件 */
        itemData={data} /* 渲染列表的数据 */
        itemCount={dataLen} /* 渲染列表的长度 */
        itemSize={100} /* 列表单项的高度  */
      />

实际结果

can not recognize item prop

An invalid "item" prop has been specified. Value should be a React component. "undefined" was specified.
Call Stack
 validateListProps
  node_modules/@tarojs/components-advanced/dist/components/virtual-list/react/validate.js:50:19
 getDerivedStateFromProps
  node_modules/@tarojs/components-advanced/dist/components/virtual-list/react/list.js:37:79
 applyDerivedStateFromProps
  node_modules/react-dom/cjs/react-dom.development.js:17876:22
 mountClassInstance
  node_modules/react-dom/cjs/react-dom.development.js:18364:5
 updateClassComponent
  node_modules/react-dom/cjs/react-dom.development.js:19713:5
 beginWork
  node_modules/react-dom/cjs/react-dom.development.js:21645:16
 HTMLUnknownElement.callCallback
  node_modules/react-dom/cjs/react-dom.development.js:4164:14
 Object.invokeGuardedCallbackDev
  node_modules/react-dom/cjs/react-dom.development.js:4213:16
 invokeGuardedCallback
  node_modules/react-dom/cjs/react-dom.development.js:4277:31
 beginWork$1
  node_modules/react-dom/cjs/react-dom.development.js:27485:7

环境信息

👽 Taro v3.6.32


  Taro CLI 3.6.32 environment info:
    System:
      OS: Linux 6.9 Fedora Linux 40 (KDE Plasma)
      Shell: 5.2.26 - /bin/bash
    Binaries:
      Node: 20.12.2 - /usr/bin/node
      npm: 10.5.0 - /usr/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.32 => 3.6.32 
      @tarojs/components: 3.6.32 => 3.6.32 
      @tarojs/helper: 3.6.32 => 3.6.32 
      @tarojs/plugin-framework-react: 3.6.32 => 3.6.32 
      @tarojs/plugin-html: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-alipay: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-h5: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-jd: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-qq: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-swan: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-tt: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-weapp: 3.6.32 => 3.6.32 
      @tarojs/react: 3.6.32 => 3.6.32 
      @tarojs/runtime: 3.6.32 => 3.6.32 
      @tarojs/shared: 3.6.32 => 3.6.32 
      @tarojs/taro: 3.6.32 => 3.6.32 
      @tarojs/taro-loader: 3.6.32 => 3.6.32 
      @tarojs/webpack5-runner: 3.6.32 => 3.6.32 
      babel-preset-taro: 3.6.32 => 3.6.32 
      eslint-config-taro: 3.6.32 => 3.6.32 
      react: ^18.0.0 => 18.3.1 

补充信息

I wanna build a dynamic dom structure without jsx sometime

@TheKonka TheKonka added V-3 Version - 3.x F-react Framework - React T-h5 Target - 编译到 H5 labels Jun 28, 2024
This was referenced Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Status: Padding
Development

No branches or pull requests

2 participants