omochi / swift-react

Scratch React implementation on Swift for Wasm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift React

Swift React is a library that implements React from scratch in Swift. Use this to implement interactive websites in Swift.

日本語はこちらです。

Overview

Swift React aims to be used in the same way as React. However, the API is designed to be Swifty. Below is an example implementation that displays "Hello world."

import React

struct App: Component {
    func render() -> Node {
        div {
            "Hello World"
        }
    }
}

Target Environments

Targeted for Swift for Wasm. Other Swift environments are not supported.

Targeted for running in web browsers. Other Wasm execution environments are not supported.

How to Use

Add it as a dependent library from Swift Package.

.package(url: "https://github.com/omochi/swift-react", from: "0.2.0")

It depends on JavaScriptKit, so when loading the Wasm binary in a web browser, it is necessary to import the JavaScript runtime library of JavaScriptKit. For more details, refer to Setting Up Environment.

Documentation

For Developers

Buildable Example

As buildable examples that operate on the browser, there are the following two sub-projects:

  • CartonExample: This is an example configuration using Carton. It is recommended to try this first.
  • BrowserTests: This is a manually constructed example. It will be helpful as a reference when making complex customizations.

Showcase

Introducing websites implemented using Swift React.

About

Scratch React implementation on Swift for Wasm

License:MIT License


Languages

Language:Swift 96.9%Language:TypeScript 2.1%Language:CSS 0.5%Language:Shell 0.3%Language:JavaScript 0.2%