Example implementations
The TypeScript client-side comes with some example implementations so you can better understand how things work.
All the example implementations contain a server-side (PHP) implementation, too:
Example implementationsMenu page
There is a PHP example implementation of a menu page, but it needs more coding not only on server-side. The entrypoint src/public/ts/admin.ts comes into game. It detects if the page is visible and automatically renders content with ReactJS. It includes - as mentioned previously - some notices and a todo list connected to a MobX store. We recommend to have a look at that files directly before we copy & paste all the stuff here again:
π
tsπ
components/*π
models/*π
store/*π
styleπ
admin.scss
π
utils/*π
admin.tsx
Widget
There is a PHP example implementation of a widget. A widget always needs a "visible part" so TypeScript together with ReactJS can do the job. We recommend to have a look at that files directly before we copy & paste all the stuff here again:
π
tsπ
styleπ
widget.scss
π
widget/*π
widget.tsx
REST endpoint
There is a PHP example implementation of a Hello World endpoint. In this case it is important to "type" that endpoint with TypeScript interfaces:
ts/wp-api/hello-world.get.tsx: Describes the GET request, parameters and response:
To request the endpoint you can simply do this by:
The resulting object will be of type ResponseRouteHelloGet and you can easily access result.hello.
Last updated
Was this helpful?