Code Monkey home page Code Monkey logo

gojsx's Introduction

gojsx

Render Jsx / Tsx / MD / MDX by Golang.

使用 Go 渲染 Jsx、Tsx、MD、MDX。

Features:

  • Pure Golang, fast and simple

Example

TSX

import App from "./App";

export default function Index(props) {
  return <html lang="en">
  <head>
    <meta charSet="UTF-8"/>
    <title>Title</title>
    <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/>
  </head>
  <body>
  <App {...props}></App>
  </body>
  </html>
}

Mdx

---
title: "Hi"
---

import Footer from "./footer.md"

# {meta.title}

<Footer/>

Render File

Then use gojsx to render .tsx or .mdx file.

package jsx

func TestJsx(t *testing.T) {
	j, err := gojsx.NewJsx(gojsx.Option{})
	if err != nil {
		t.Fatal(err)
	}

	s, err := j.Render("./test/Index.jsx", map[string]interface{}{"li": []int64{1, 2, 3, 4}})
	if err != nil {
		t.Fatal(err)
	}

	t.Logf("%+v", s)
}

Defects

How to bind event? e.g. onClick

Since the binding event must happen on the browser, and jsx is js code, the browser needs to run the entire jsx component to bind the event correctly, which requires the introduction of react at the front end, otherwise it is very complicated to implement, but the use react will cause jsx to no longer be pure jsx, which in turn will cause gojsx to become more complicated.

So gojsx can't implement event binding that uses simple react syntax.

To save the day, you can either write your own js to manipulate the dom (as everyone did in the JQuery days), or use a library like AlpineJs.

Dependents

gojsx's People

Contributors

zbysir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.