GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Nullstack
  • What is Nullstack?
  • Documentation
  • Examples
  • Contributors
  • F.A.Q
  • Waifu
  • Português
  • Star
  • Stateless Components
  • Stateful components
  • Full stack lifecycle
  • Server functions
  • Context

This view

  • Original page
  • New address

GeezerVison is showing nullstack.app — Stateless Components - Nullstack

Stateless Components

Stateless components are pure functions that return JSX.

JSX is an XML/HTML-like syntax that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript.

Stateless components are very similar to web components, they give you the ability to create new HTML tags that shortcut a group of other HTML tags.

Create a file in your src folder with the name of your component and the jsx extension.

The props passed to a component can be destructured in the function signature

// src/HelloDweeb.jsx
export default function HelloDweeb({ name }) {
  return <p> Hello {name} </p>
}
// src/Application.jsx
import HelloDweeb from './HelloDweeb';

export default function Application({ name }) {
  return (
    <div>
      <HelloDweeb name="Anny">
    </div>
  )
}

Stateless components have access to the client context and props are merged into the specific context

// src/HelloProject.tsx
import { NullstackClientContext } from 'nullstack'

interface HelloProjectProps {
  name: string
}

export default function HelloProject(context: HelloProjectProps) {
  const { project, name } = context as NullstackClientContext<HelloProjectProps>
  return <p> Hello {name} welcome to {project.name} </p>
}
// src/Application.tsx
import HelloProject from './HelloProject';

export default function Application() {
  return (
    <div>
      <HelloProject name="Bilkaya">
    </div>
  )
}

Next Step

➡️ Learn more about Core Features: Stateful components❓ Have any questions or suggestions? Join our Discord
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.