
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-directus
Advanced tools
A set of React components and utilities for Directus Headless CMS.
Install this library along with @directus/sdk:
npm install react-directus @directus/sdk
The <DirectusProvider> component makes the Directus JavaScript SDK available to any nested components that need to access it. Assuming that <App /> component is your root component:
import { App } from './App';
import { DirectusProvider } from 'react-directus';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<DirectusProvider apiUrl="https://api.example.com">
<App />
</DirectusProvider>,
document.getElementById('root')
);
You can optionally pass an apiOptions object to the provider, it will be passed to the client as the init parameter.
useDirectusAfter adding the provider, you can access the configured client anywhere in the app, using the useDirectus hook:
import React, { useEffect, useState } from 'react';
import { useDirectus } from 'react-directus'
export const TodoList = () => {
// Get the Directus SDK object
const { directus } = useDirectus();
const [todos, setTodos] = useState([]);
useEffect(() => {
const fetchTodos = async () => {
const todos = (await directus.items('todos').readMany()).data;
setTodos(todos);
};
fetchTodos();
}, [directus]);
return todos.map(item => <TodoItem key={item.id} item={item} />);
};
The hook exports a few components for working with Direcuts files file access. They are all configured for using the apiUrl specified in the provider. Hopefully, more will come in the future 🤗.
All components, when imported from
react-directusdirectly (i.e. not imported using the hookuseDirectus), can be used in a "standalone" way. It means that they are not bound to theapiUrlspecified in the provider. In that case, they both accept anapiUrlprop.
<DirectusAsset>Computes the URL of the given resource asset, rendering it using the render prop:
asset: the asset representing the resource (string or object with an id property)download: force browser to download the asset (force the Content-Disposition header)render: a function (which receives an object with the url property) that provides the component to renderimport React from 'react';
import { useDirectus } from 'react-directus';
export const TodoItem = ({ item }) => {
const { DirectusAsset } = useDirectus();
return (
<div>
<h1>Todo #{item.id}</h1>
<DirectusAsset asset={item.attachment} download={true}
render={({ asset, url }) => <a href={url}>{asset.filename_download}</a>} />
</div>
);
};
<DirectusImage>Computes the URL of the given resource asset, rendering it using the render prop:
asset: the asset representing the resource (string or object with an id property)fit: fit of the thumbnail while always preserving the aspect ratio, can be any of the following options: cover, contain, inside or outsideheight: height of the thumbnail in pixelsquality: quality of the thumbnail (1 to 100)width: width of the thumbnail in pixelsrender: a function (which receives an object with the url property) that provides the component to renderimport React from 'react';
import { useDirectus } from 'react-directus';
export const TodoItem = ({ item }) => {
const { DirectusImage } = useDirectus();
return (
<div>
<h1>Todo #{item.id}</h1>
<DirectusImage asset={item.image} fit="cover" quality="75"
render={({ asset, url }) => <img src={url} alt={asset.title} />} />
</div>
);
};
New features and bug-fix are always welcome! In order to contribute to this project, follow a few easy steps:
npm installmy-awesome-feature and commit to itnpm run lint, npm run test and npm run build and verify that they complete without errorsmy-awesome-feature branch to GitHub and open a pull requestFAQs
A set of React components and utilities for Directus Headless CMS
The npm package react-directus receives a total of 1 weekly downloads. As such, react-directus popularity was classified as not popular.
We found that react-directus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.