Skip to content

Commit

Permalink
Fixed lint warnings and errors and formatted examples
Browse files Browse the repository at this point in the history
  • Loading branch information
matux committed Feb 24, 2024
1 parent ce95fdf commit 8703f83
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 212 deletions.
52 changes: 28 additions & 24 deletions examples/create-react-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
Provider as RollbarProvider,
ErrorBoundary,
RollbarContext,
useRollbar
useRollbar,
} from '@rollbar/react'

import './App.css';
import './App.css'

const rollbarConfig = {
accessToken: process.env.REACT_APP_PUBLIC_ROLLBAR_TOKEN,
hostSafeList: [
'localhost:3000',
'localhost:4000',
],
hostSafeList: ['localhost:3000', 'localhost:4000'],
captureUncaught: true,
captureUnhandledRejections: true,
payload: {
Expand All @@ -26,15 +23,17 @@ const rollbarConfig = {
},
},
},
};
}

function App() {
return (
<RollbarProvider config={rollbarConfig}>
<ErrorBoundary
level="critical"
errorMessage="example error boundary message"
fallbackUI={() => <p style={{ color: 'red' }}>Oops, there was an error.</p>}
fallbackUI={() => (
<p style={{ color: 'red' }}>Oops, there was an error.</p>
)}
extra={{ more: 'data' }}
callback={() => console.log('an exception was sent to rollbar')}
>
Expand All @@ -51,61 +50,66 @@ function App() {
<Router />
</ErrorBoundary>
</RollbarProvider>
);
)
}

export default App;
export default App

function Router() {
return (
<Routes>
<Route path="a" element={<RouteA />} />
<Route path="b" element={<RouteB />} />
</Routes>
);
)
}

function RouteA() {
const rollbar = useRollbar();
const rollbar = useRollbar()

const [message, setMessage] = useState('example');
const [message, setMessage] = useState('example')

const fullMessage = useMemo(() => `Hello, ${message}!`, [message]);
const fullMessage = useMemo(() => `Hello, ${message}!`, [message])

return (
<RollbarContext context="/a-context">
<h1>A</h1>
<p>Message: {fullMessage}</p>
<input value={message} onChange={(event) => setMessage(event.target.value)} />
<input
value={message}
onChange={(event) => setMessage(event.target.value)}
/>
<br />
<button onClick={() => rollbar.info(`Hello, ${message}.`)}>send message</button>
<button onClick={() => rollbar.info(`Hello, ${message}.`)}>
send message
</button>
</RollbarContext>
);
)
}

function RouteB() {
const [errorState, setErrorState] = useState({ error: false });
const [errorState, setErrorState] = useState({ error: false })

const updateErrorState = () => {
// Use an error state and throw inside render,
// because React won't send errors within event handlers
// to the error boundary component.
setErrorState({
error: true
});
};
error: true,
})
}

if (errorState.error) {
// This uncaught error will be handled by the ErrorBoundary.
throw new Error('uncaught test error');
throw new Error('uncaught test error')
}

return (
<RollbarContext context="/b-context">
<h1>B</h1>
<button id='uncaught-error' onClick={updateErrorState}>
<button id="uncaught-error" onClick={updateErrorState}>
Throw Uncaught Error
</button>
</RollbarContext>
);
)
}
12 changes: 6 additions & 6 deletions examples/create-react-app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';
import { render, screen } from '@testing-library/react'
import App from './App'

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
render(<App />)
const linkElement = screen.getByText(/learn react/i)
expect(linkElement).toBeInTheDocument()
})
16 changes: 8 additions & 8 deletions examples/create-react-app/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from "react-router-dom";
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter } from 'react-router-dom'
import './index.css'
import App from './App'
import reportWebVitals from './reportWebVitals'

ReactDOM.render(
<React.StrictMode>
Expand All @@ -12,9 +12,9 @@ ReactDOM.render(
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root')
);
)

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
reportWebVitals()
2 changes: 1 addition & 1 deletion examples/create-react-app/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions examples/create-react-app/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const reportWebVitals = onPerfEntry => {
const reportWebVitals = (onPerfEntry) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
getCLS(onPerfEntry)
getFID(onPerfEntry)
getFCP(onPerfEntry)
getLCP(onPerfEntry)
getTTFB(onPerfEntry)
})
}
};
}

export default reportWebVitals;
export default reportWebVitals
2 changes: 1 addition & 1 deletion examples/create-react-app/src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import '@testing-library/jest-dom'
Loading

0 comments on commit 8703f83

Please sign in to comment.