Integrations
How to use this SDK within your favorite Framework. ๐
React
Create a strapi.js
file to set up your Strapi SDK instance. Then, import this file wherever you need to use it.
strapi.js
import Strapi from 'strapi-sdk-js'
export const strapi = new Strapi({
// ...options
})
Nuxt 3
If you want to easily fetch your Strapi content from a Nuxt 3 application, you can check the Strapi module developed by the Nuxt team.
Unlike Nuxt 2, you only need to set up a plugin
, and then you can simply access $strapi
using useNuxtApp
wherever you need to use it.
~/plugins/strapi.js
import { defineNuxtPlugin } from '#app'
import Strapi from 'strapi-sdk-js'
export default defineNuxtPlugin(() => {
const strapi = new Strapi({
// options
})
return {
provide: {
strapi,
},
}
})
Nuxt 2
To use the Strapi SDK
globally, set up a plugin
and include it in the nuxt.config.js
file:
~/plugins/strapi.js
import Strapi from 'strapi-sdk-js'
export default (_, inject) => {
const strapi = new Strapi({
// options
})
inject('strapi', strapi)
}
Now, you can use it globally with this.$strapi
in components and app.$strapi
in the asyncData
function.
Webpack
In some case, your webpack based application will not support by default .mjs
files. In order to fix this you can update your webpack config with the following configuration:
webpack.config.js
module.exports = {
// ...other configuration options
resolve: {
extensions: [..., '.mjs'], // Add '.mjs' to the list of extensions
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto', // Use the 'javascript/auto' type for .mjs files
},
],
},
}