@railtownai/react
v2.0.21
Published
React components that integrate with Railtown AI
Downloads
101
Keywords
Readme
Railtown AI for React apps
Railtown AI root cause analysis for React apps.
Getting Started
- Sign up for a free account at railtown.ai.
- Copy your Railtown API Token from the Project Configuration page
- Install the package:
npm install --save @railtownai/react
oryarn add @railtownai/react
- Follow the instructions below to integrate Railtown AI into your React app(s)
Installation
// main.tsx or index.tsx
import React from "react";
import * as RailtownAI from "@railtownai/react";
RailtownAI.install({
token: YOUR_RAILTOWN_TOKEN,
userProperties: {
ignoreErrors: ["Error Message", /Exact Error Message/],
},
});
function App() {
return (
<>
<h1>Hello Railtown AI!</h1>
<RailtownAI.ErrorBoundary fallback={<div>This is a fallback to the error</div>}>
<SomeErroneousComponent />
</RailtownAI.ErrorBoundary>
</>
);
}
const container = document.getElementById("app");
const root = ReactDOM.createRoot(container);
root.render(<App />);
Usage with useLogger()
// UserList.tsx
import React from "react";
import { useLogger } from "@railtownai/react";
const UserList = (props) => {
const logger = useLogger();
const [users, setUsers] = React.useState([]);
useEffect(() => {
(async () => {
try {
const response = await fetch("https://jsonplaceholder.typicode.com/users");
const users = await response.json();
setUsers(users);
} catch (error) {
logger.error(error);
}
})();
}, []);
return (
<>
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</>
);
};
export { UserList };