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

Implemented StrictMode into Haxe-React, and possibly more #147

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Just-Feeshy
Copy link

Added StrictMode as a static variable to our React extern class in Haxe. It's now possible to use React.StrictMode in the same way as any other React component in our Haxe-React codebase.

Here's an example:

import js.Browser.document;

import react.ReactDOM;
import react.ReactComponent;
import react.ReactMacro.jsx;
import react.React;

@:jsRequire("./App.jsx", "default")
extern class App {}

function main() {
    js.Lib.require("./index.css");

    ReactDOM.render(
        jsx("<React.StrictMode><App /></React.StrictMode>"),
        document.getElementById("root")
    );
}

Just-Feeshy and others added 8 commits July 2, 2023 06:39
This commit is suppose to help with Haxe being able to support other JS frameworks like WebPacket, NextJs, and Vite.
react.Component isn't a main is suppose to be imported directly.
Modernized by adding `useState` and `useEffect`
There is no point of having both useEffect and useState since I find using the ReactHooks much easier to work with.
@Just-Feeshy
Copy link
Author

Just-Feeshy commented Jul 28, 2023

In this example, the ReactDOMClient.createRoot() function is used to create a root node on an HTML element (with the id "root"). This method is part of the new React 18 root API and provides built-in support for concurrent rendering.

After creating a root, the render method is called on with the JSX to be rendered wrapped in <React.StrictMode> component.

NOTE: I recommend using ViteJS if you're going to do this setup for your project. This is to demonstrate the new ReactDOMClient for React 18 for Haxe.

package;

import js.Browser.document;

import js.html.Element;
import react.ReactDOMClient;
import react.React;

function main() {
    var rootElement = document.getElementById("root");
    var root = ReactDOMClient.createRoot(rootElement);

    root.render(
        jsx('
            <React.StrictMode>
                <h1>Hello World!</h1>
            </React.StrictMode>
        ')
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant