Skip to content

Commit

Permalink
add usage of createElement from React.createElement (tscircuit#511)
Browse files Browse the repository at this point in the history
* add usage of createElement from React.createElement

* Update lib/index.ts

---------

Co-authored-by: Severin Ibarluzea <[email protected]>
  • Loading branch information
Anshgrover23 and seveibar authored Jan 11, 2025
1 parent 9175e1f commit 034efa1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export * from "./utils/public-exports"
// Allows easier introspection of render process
export * from "./components/base-components/Renderable"

export { createElement } from "react"

import "./register-catalogue"
import "./fiber/intrinsic-jsx"
24 changes: 24 additions & 0 deletions tests/createElementUsage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { it, expect } from "bun:test"
import "lib/register-catalogue"
import { Circuit, createElement } from "../index"

it("should allow usage of createElement without explicit React import", () => {
const circuit = new Circuit()
const groupElm = createElement(
"group",
{},
createElement("led", { name: "LED2", footprint: "0402" }),
createElement("resistor", {
name: "R1",
resistance: "10k",
footprint: "0402",
}),
)

circuit.add(groupElm)
circuit.render()

// Check that the circuit has the LED and resistor
expect(circuit.db.source_component.select(".LED2")?.name).toBe("LED2")
expect(circuit.db.source_component.select(".R1")?.name).toBe("R1")
})

0 comments on commit 034efa1

Please sign in to comment.