Preact: forwardRef: cannot assign name

Created on 20 Dec 2019  路  2Comments  路  Source: preactjs/preact

In React you can assign name to a component wrapped with forwardRef. This enables correct component names in stack traces.

However, in Preact you can't do this because name property of such component is read-only. So you get an error: Cannot assign to read only property 'name' of function.

Example: https://github.com/mlshv/preact-forwardref-name. You can switch react/preact in config-overrides.js

wontfix

Most helpful comment

Use displayName instead of name. The latter is read-only for standard JavaScript functions per spec.

All 2 comments

Use displayName instead of name. The latter is read-only for standard JavaScript functions per spec.

Ah yep, I wouldn't count on this ever being supported. Even if it works in this one case in React, it'll break in many others (depending on the browser).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriaanwm picture adriaanwm  路  3Comments

nopantsmonkey picture nopantsmonkey  路  3Comments

KnisterPeter picture KnisterPeter  路  3Comments

matthewmueller picture matthewmueller  路  3Comments

philipwalton picture philipwalton  路  3Comments