Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Commit 1133be5

Browse files
committed
Add invariant check that verifies that the correct type of react element is passed to ReactWidget
1 parent 68ce89b commit 1133be5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/react4j/widget/ReactWidget.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import java.util.Objects;
77
import javax.annotation.Nonnull;
88
import jsinterop.base.Js;
9+
import org.realityforge.braincheck.BrainCheckConfig;
10+
import react4j.core.React;
911
import react4j.core.ReactNode;
1012
import react4j.dom.ReactDOM;
13+
import static org.realityforge.braincheck.Guards.apiInvariant;
1114

1215
/**
1316
* A GWT widget that renders a React4j element.
@@ -33,6 +36,11 @@ public ReactWidget( @Nonnull final ReactNode node )
3336
{
3437
_element = Document.get().createDivElement();
3538
_node = Objects.requireNonNull( node );
39+
if ( BrainCheckConfig.checkApiInvariants() )
40+
{
41+
apiInvariant( () -> React.isValidElement( node ),
42+
() -> "A ReactNode that is not a valid element has been incorrectly passed to ReactWidget constructor" );
43+
}
3644
setElement( _element );
3745
}
3846

0 commit comments

Comments
 (0)