title |
---|
Custom compilation flags |
This is not a custom compilation flag, but it enables/disables some features in haxe-react. Basically, you'll want to compile with it when using dev version of react, and remove it when using prod version.
By default, when building for release (eg. without -debug
), calls to
React.createElement
are replaced by inline JS objects (if possible). This can
also be disabled with -D react_no_inline
.
See: facebook/react#3228
// regular
return React.createElement('div', {key:'bar', className:'foo'});
// inlined (simplified)
return {$$typeof:Symbol.for('react.element'), type:'div', props:{className:'foo'}, key:'bar'}
When compiling in debug mode, display names are added for your components, for use with your browser's react developer tools.
Some react shared internals data are only available when compiling in debug mode (and using dev version of react), for advanced debugging.
Haxe-react adds some runtime warnings when enabled with both debug mode and
-D react_runtime_warnings
. There is still work to be done here, especially
with the re-render warnings that have some false positives atm.
This warnings include:
-
Runtime warnings about avoidable re-renders, unless you also compile with
-D react_runtime_warnings_ignore_rerender
or for a specific component if you add a@:ignoreRenderWarning
meta to it. This feature can be disabled because it can have false positives when dealing with legacy context API or hot reloading. -
Runtime errors when a stateful component does not initialize its state inside its constructor. There would be errors thrown by react later in the component lifecycle, but without the source cause.
js.Browser.console.error( 'Warning: component ${inClass.name} is stateful but its ' + '`state` is not initialized inside its constructor.\n\n' + 'Either add a `state = { ... }` statement to its constructor ' + 'or define this component as a `ReactComponentOfProps` ' + 'if it is only using `props`.\n\n' + 'If it is using neither `props` nor `state`, you might ' + 'consider using `@:jsxStatic` to avoid unneeded lifecycle. ' + 'See https://github.com/kLabz/haxe-react/blob/next/doc/static-components.md ' + 'for more information on static components.' );
ReactType
adds a runtime error when a node ends up with a null
value, which
is usually due to an extern component not resolving to its real value.
Use this compilation flag when you are loading react by embedding react js files
in your HTML page (instead of using require()
from modular or webpack).
Adds some data needed for react hot reloading with modular / webpack. See haxe-modular documentation.
The context
field on ReactComponent
has been removed because it has been
deprecated in react and its use as a class field is discouraged. You can add it
back with this flag if needed.
Jsx parser currently cannot apply type checker on some components (see #7) and will produce warnings.
This compilation flags disable these warnings.
Enable strict mode for @:wrap
HOC wrapping. This will ensure you define the
public props type of your component wrapped with @:wrap
so that jsx type
checking can be done.
See Wrapping your components in HOCs.
Enable prototype type checker for @:jsxStatic
expressions.
Since affd6e4a
, aria-*
props are type-checked against their
specification, and enums are provided where necessary (see
react.jsx.AriaAttributes
). They are enabled by default for both html elements
and react components. You can disable support for aria-*
props entirely with
-D react_jsx_no_aria
, or only disable it for react components with
-D react_jsx_no_aria_for_components
.
Since affd6e4a
, data-*
props are enabled by default for react
components (all unknown props are already accepted for html elements), with a
type of Dynamic
. This behavior can be disabled with
-D react_jsx_no_data_for_components
, meaning that data-*
props need to be
explicitely accepted by the components (which is currently not that easy in
Haxe).
Haxe 4 introduces inline xml-like markup, allowing us to drop the strings in our
jsx(...)
expressions.
With this option, react-next
goes one step further and automatically wraps all
xml markup in render
(and also renderSomething
) functions in classes
extending ReactComponent
in a call to ReactMacro.jsx()
, as well as in the
methods used in @:jsxStatic(myMethod)
.
Note that this feature has been reported to be incompatible with cococonut
.