Learn how to get started with Elements in a React project.
Use the React App template to create a new Elements website in React without any additional setup.
npx [email protected] my-dir --template @stoplight/elements
Then, run cd my-dir
and yarn start
to see a basic Elements website in the browser.
To install Elements Dev Portal in an existing React app, follow these instructions.
- Install the
@stoplight/elements
package with NPM/Yarn.
yarn add @stoplight/elements
- In
App.js
import the API component and CSS file from the Elements library.
import { API } from '@stoplight/elements';
import '@stoplight/elements/styles.min.css';
- Add the App component to the output of the app.
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
/>
- Now your
App.js
file should look something like this:
import React from 'react';
import { API } from '@stoplight/elements';
import '@stoplight/elements/styles.min.css';
function App() {
return (
<div className="App">
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
/>
</div>
);
}
export default App;
Now start the development server.
yarn start
And you should see the API reference documentation for the Zoom API.
See Elements Configuration Options.
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
router="hash"
/>
import { API } from "@stoplight/elements";
const apiDescriptionDocument = {
openapi: '3.1.0',
info: {
title: 'Some Awesome API',
version: '1.0.0'
},
paths: {
/* ... */
}
};
<API
apiDescriptionDocument={apiDescriptionDocument}
router="hash"
/>