Building a custom component

Under the reactproject folder, create a new folder called hello_message. Inside the folder, we'll create a new file called hello_message.go. In the file, we will call the hellomessage package:

package hellomessage

We then create a Go struct to represent our React component:

import "myitcv.io/react"type HelloMessageDef struct {  react.ComponentDef}

Now, it's time to define our props. This can simply be done by a struct type that contains our expected props. As mentioned, our prop is the message string:

//Naming convention is *propstype HelloMessageProps struct {  Message string}

Defining a state object is very similar to props. A struct type needs to be created with the expected React state object fields. Our state ...

Get Hands-On Full Stack Development with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.