The application instance
Every Spec application starts by creating a new application instance with the createApp function:
JS
The Root Component
The object we are passing into createApp is in fact a component. Every app requires a "root component" that can contain other components as its children.
Terminal
While many examples in this guide only need a single component, most real applications are organized into a tree of nested, reusable components. For example, a Todo application's component tree might look like this:
Terminal
Sections of the guide, we will discuss how to define and compose multiple components together. Before that, we will focus on what happens inside a single component.
Mounting the App
An application instance won't render anything until its .mount() method is called. It expects a "container" argument, which can either be an actual DOM element or a selector string:
Terminal
Composing Client and Server Components
Server and Client Components can be combined in the same component tree. Behind the scenes, React handles rendering as follows:
Nesting Server Components inside Client Components
Given the rendering flow outlined above, there is a restriction around importing a Server Component into a Client Component, as this approach would require an additional server round trip.
Unsupported Pattern: Importing Server Components into Client Components The following pattern is not supported. You cannot import a Server Component into a Client Component:
package.json
What do you need to do?
Server Component
Client Component
Access backend resources
None
Add interactivity and event
React Essentials
Building Your Application
TypeScript