项目
在 GitHub 查看
ascorbic/use-php
关于
Use PHP in React
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文🏎️ usePHP 💨
A React hook for running PHP? Why not?
It runs in a Netlify Edge Function and uses php-wasm to execute the PHP. It runs asynchronously, so you need a renderer that supports async components.
Usage
/** @jsx h */
import { h, renderToString } from "https://deno.land/x/jsx/mod.ts";
import { usePHP } from "https://deno.land/x/use_php/mod.ts";
export default async function handler(request: Request) {
const php = await usePHP(request, h);
return new Response(
await renderToString(
<html>
<head>
<title>Use PHP</title>
</head>
<body>
{await php`
<?php phpinfo(); ?>
`}
</body>
</html>
),
{
headers: {
"content-type": "text/html; charset=UTF-8",
},
}
);
}
export const config = {
path: "/*",
excluded_paths: "/public/*",
};
API
usePHP(request: Request, renderer?: JSXRenderer)
Pass in the request object and an optional JSX renderer and it will return tagged template that you can use to execute PHP. If you pass a JSX render function to the hook (e.g. h or React.createElement), then the template will return a JSX element. If you omit the renderer it will return an HTML string instead.
Try it yourself:
FAQ
- Why?
- Why not? That Lambo won't buy itself.
- How can I deploy this to production?
- 🤦🏻♂️
LICENCE
MIT Licence. © 2023 Matt Kane
探索相关项目
加载中…