-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pass the children attribute as-is to the react component
Related to #43
- Loading branch information
Showing
4 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts"> | ||
import { createElement } from "react"; | ||
import Search from "./Search"; | ||
let query = $state("123"); | ||
const react = sveltify({ Search }); | ||
</script> | ||
|
||
<input type="search" bind:value={query} /> | ||
|
||
<react.Search | ||
{query} | ||
children={(results) => | ||
results.map((result, i) => createElement("div", { key: i }, result))} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type Props = { | ||
query: string; | ||
children: (results: string[]) => React.ReactNode; | ||
}; | ||
export default function Search({ query, children }: Props) { | ||
// The number of results is determined by the length of the query string. | ||
const results: string[] = new Array(query.length) | ||
.fill(null) | ||
.map((_, i) => `result ${i + 1} with ${query}`); | ||
|
||
return children(results); | ||
} |