Bug: React.isValidElement( ) Unable to check the hok function component

This issue has been created since 2022-11-11.

React version:

Steps To Reproduce

Link to code example:

The current behavior

The expected behavior

React.isValidElement( ) Unable to check the hook function component ,

With the hook function component, babel, which is compiled into es5 code, is sometimes not executed with createElement, but mutated into a function, Like the compiled code in the image below。
123456

It's not compiled like this
image

But rendering is fine。

But my react route requires the isValidElement api,Because I want to know whether the current variable is a component or a function, and choose a different way to execute it。
the reason for this problem is that my imported component is in promise mode.

If you have time, can you help me look at this bug?

Here's how I wrote react-lazy-router-dom https://github.com/qq281113270/react-lazy-router-dom ,I need this isValidElement to determine whether it's a component or a function 。

In addition, if you think I wrote react-lazy-router-dom well, could you please help me make a friendship link

eps1lon wrote this answer on 2022-11-11

I need this isValidElement to determine whether it's a component or a function

isValidElement cannot distinguish component from function:

isValidElement(<Component />); // true
isValidElement(Component); // false
isValidElement(() => <Component />); // false
qq281113270 wrote this answer on 2022-11-30

I need this isValidElement to determine whether it's a component or a function

isValidElement cannot distinguish component from function:

isValidElement(<Component />); // true
isValidElement(Component); // false
isValidElement(() => <Component />); // false

I need this isValidElement to determine whether it's a component or a function

isValidElement cannot distinguish component from function:

isValidElement(<Component />); // true
isValidElement(Component); // false
isValidElement(() => <Component />); // false

isValidElement(); , The judgment is inaccurate。
test code

const lazy = (loader) => {
  lazy.loaderArr = [...lazy.loaderArr, loader];
  return () => {
    return loader()
      .then((res) => {
        return res.default;
      })
      .catch((e) => {
        throw new Error(e);
      });
  };
};
lazy.loaderArr = [];


 let = Component = lazy(() =>
      import(
        /* webpackChunkName:"accountManagementDetails" */ 

      "client/pages/Index/pages/system/pages/AccountManagement/index.js"  // this is  Component  path

      )
    )
    console.log("Component===", Component);
    console.log("<Component/>==", <Component />);
    console.log("isValidElement==", isValidElement(<Component />));
    debugger;

If I use ,He will become a vnode,
isValidElement() Will return true。
But Component isn't really a component, it's a component promise loader。 expect Will return false。 So isValidElement can't tell if it's a real component.

test result
image

Is there any other way you can tell if it's a component or a function or a promise.

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-12-01
Star Count 198482
Watcher Count 6646
Fork Count 41196
Issue Count 1106

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Sliders disapear in Pose Mode 5 2019-08-07 2022-11-13
Build static lib without blas 16 2020-08-07 2022-10-30
Temporal filename "yt_videos_list_temp.txt" 9 2020-11-14 2022-07-24
Is possible FIDO server run on Apache Tomcat ? 2 2022-03-09 2022-10-05
plugins para Bagisto 1 2021-05-10 2022-10-20
Inspecific error message during configuraiton update 0 2022-06-23 2022-10-07
Grab the innerHTML 2 2019-02-25 2022-01-14
Allow customizing formatter 4 2019-10-25 2022-10-15
"Do not discard when it's pinned" is not preserved in Firefox 2 2021-12-16 2022-11-23
tests: (lsfd) fix file descriptor leaks reported by coverity 0 2021-11-29 2022-08-30
CGAL Minkowski sum assertion when performing union operation of Nef_polyhedron_3 0 2022-10-18 2022-11-28
requests.exceptions.SSLError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 4 2022-01-28 2022-11-24
About reported security vulnerability on huntr.dev 0 2022-05-20 2022-11-15
Config - incompatible function signatures 6 2022-02-14 2022-11-19
All instances not created with load_mask() and not visualized with display_instances() 0 2022-01-07 2022-11-15
Cleanup UndefinedClassTest 0 2021-11-17 2022-11-28
Create / name / rename Page: a great pity that the most important basic functions are not intuitive 1 2022-10-26 2022-11-20
Use on React Native 11 2019-11-23 2022-01-06
Can't detect the config diff to import or export configurations 2 2021-08-12 2022-10-04
Support for different SLO time windows 7 2021-06-17 2022-10-29
Istio component configuration for sidecar migration 0 2022-07-12 2022-11-17
EXC_BAD_ACCESS (code=2, address=0x16d0f3ff0) 2 2021-02-12 2022-11-19
PANIC: Unknown column type 243 in /root/.cargo/registry/src/github.com-1ecc6299db9ec823/mysql_common-0.26.0/src/constants.rs:498:18 2 2022-01-31 2022-10-27
Followed instructions however certification not showing for localhost 1 2021-08-08 2022-11-20
color-picker 组件增加自定义预设颜色 最好能增加颜色吸取功能 9 2021-10-04 2022-11-29
bindkey_o requires a concrete object (got a NQPMu type object instead) 17 2019-11-14 2022-11-08
Make a raptotheosis.1 man page 3 2021-02-24 2022-07-23
Allows enum to be upper and lowercase 2 2022-11-24 2022-11-29
use `_default` instead of nothing as dest in complete_zsh 7 2022-02-18 2022-11-22
ci(node): drop support for node 10 5 2021-12-07 2022-09-27
request: add wlroots-eglstreams and config to build/cache pkgs built with it 6 2021-07-30 2022-11-30
AnimationPlayer external broken animation resource causes the scene to crash on open 2 2022-06-16 2022-11-15
部分视频播放时会自动跳转到第二秒导致音画不同步 v4.41-4.47 0 2022-09-07 2022-10-28
增加固定标签页功能, 关闭后重启能还原上次标签页 0 2022-07-01 2022-10-28
同一个代理服务器时,港澳台番剧网页版可以播放,但UWP无法播放。 8 2022-08-10 2022-10-28
The repl.it auth does not work 0 2021-01-04 2022-11-25
世界地图中,填充区绑定click事件,无任何回调 1 2021-07-01 2022-10-14
Interpretation of results 1 2021-11-02 2022-11-12
services/horizon: Update TestProtocol14StateVerifier to test LiquidityPoolEntry 1 2021-08-27 2022-10-14
Unable mkdir /cache/recovery after rebooting into recovery mode 4 2021-08-07 2022-10-15
Distance snap not snapping to radius 4 2022-11-21 2022-11-28
[BUG] 1.x changes can break builds on main 2 2022-03-04 2022-10-04
[QUESTION] 数据库迁移字段修改文档问题 1 2021-10-14 2022-11-03
Error during OpenSSL build on Windows 5 2021-11-18 2022-11-28
export and import of custom filter lists. 0 2022-09-13 2022-09-09
impossible to translate part of page 1 2022-09-13 2022-09-09
Enabling commit c12bf15 on branch 1.2.X 2 2020-03-09 2022-10-17
How to get the memory size of value type correctly in Windbg with SOS extension? 4 2022-04-12 2022-11-30
Bulk delete with join 2 2022-09-14 2022-09-12
Auto migrations with GenerateScript 3 2022-09-15 2022-09-22