An open API service indexing awesome lists of open source software.

https://github.com/tsedio/tsed-browser-example

Use @tsed/di in a React project
https://github.com/tsedio/tsed-browser-example

injection-dependency reactjs tsed

Last synced: 24 days ago
JSON representation

Use @tsed/di in a React project

Awesome Lists containing this project

README

          


Ts.ED logo


@tsed/di + React.js





Website
  •  
Getting started
  •  
Slack
  •  
Twitter



> Use @tsed/di with React.js to build your website with Vite 4 and Ts.ED.

## Features

- Ts.ED
- Vite
- React 19

## Example

```tsx
import {useEffect, useState} from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import {HttpClient} from "./services/HttpClient.js";
import {inject} from "@tsed/di";

function App() {
const [count, setCount] = useState(0)
const [tsedApi, setTsedApi] = useState<{ version: string; modules: Record } | null>(null)

useEffect(() => {
const httpClient = inject(HttpClient)

httpClient.get("https://tsed.dev/api.json")
.then((value) => {
setTsedApi(value)
})
}, [])

return (
<>



Vite logo


React logo


Ts.ED logo


Vite + React + Ts.ED



setCount((count) => count + 1)}>
count is {count}


Edit src/App.tsx and save to test HMR




Click on the Vite and React logos to learn more


Ts.ED {tsedApi?.version}


Use @tsed/di to inject create and inject services like HttpClient and fetch data from your
backend.

Modules


    {
    Object.entries(tsedApi?.modules || {}).map(([name]) => (

  • {name}

  • ))
    }


>
)
}

export default App
```

## Contributors

Please read [contributing guidelines here](./CONTRIBUTING.md).

## Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]

## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]

## License

The MIT License (MIT)

Copyright (c) 2016 - Today Romain Lenzotti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.