Introduction
React4j is an opinionated abstraction on top of ReactJS that allows you to use Java
to build a web application using the React component model. The React component model
defines components that are passed props
by their container, manage their own state
and can be composed
to make complex UIs.
React4j uses GWT or J2CL to compile the Java code to Javascript.
The "Hello World" of React4j that just returns a header is as simple as:
ReactDOM.render( h1( "Hello World" ), WindowGlobal.document().getElementById( "app" ) );
Although there is significantly more ceremony in java. You also need an xml based build descriptor for GWT which serves a similar purpose as a webpack configuration.
package react4j.examples.hello_world;
import akasha.WindowGlobal;
import com.google.gwt.core.client.EntryPoint;
import react4j.dom.ReactDOM;
import static react4j.dom.DOM.*;
public class HelloWorld
implements EntryPoint
{
public void onModuleLoad()
{
ReactDOM.render( h1( "Hello World" ), WindowGlobal.document().getElementById( "app" ) );
}
}
<module rename-to='hello_world'>
<inherits name="com.google.gwt.core.Core"/>
<inherits name="react4j.dom.Dom"/>
<entry-point class='react4j.examples.hello_world.HelloWorld'/>
<source path=''/>
<public path='public'/>
<set-property name="jre.checks.checkLevel" value="MINIMAL"/>
<collapse-all-properties/>
</module>