Swift React is a library that implements React from scratch in Swift. Use this to implement interactive websites in Swift.
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"
}
}
}
Targeted for Swift for Wasm. Other Swift environments are not supported.
Targeted for running in web browsers. Other Wasm execution environments are not supported.
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.
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.
Introducing websites implemented using Swift React.
- Swift String Counter (GitHub): A web page for counting characters.