npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oak-digital/nextjs-strapi-image

v0.0.3

Published

Small wrapper for next/image, to easily populate strapi media attributes

Downloads

83

Readme

Nextjs Strapi image component

This library provides a small wrapper for next/image that populates the values from a media coming from strapi.

It automatically populates the following props src, width, height and alt;

Getting started

Installation

Install the library

# pnpm
pnpm install @oak-digital/nextjs-strapi-image
# npm
npm install @oak-digital/nextjs-strapi-image
# yarn
yarn add @oak-digital/nextjs-strapi-image

Usage

Basic usage

The component can be imported easily. The media prop should be the object that contains id and attributes key.

Media data example:

{
    "id": 1,
    "attributes": {
        "name": "x.jpg",
        "alternativeText": null,
        "caption": null,
        "width": 2880,
        "height": 1920,
        "formats": {
        },
        "url": "/uploads/x.jpg",
        "previewUrl": null,
        "provider": "local",
        "provider_metadata": null,
        ...
    }
}

Basic usage

import { StrapiImage } from '@oak-digital/next-strapi-image';

const MyComponent = ({ media }) => {
    return (
        <div>
            {/* ... */}
            <StrapiImage media={media} strapiUrl={process.env.NEXT_PUBLIC_STRAPI_URL} />
        </div>
    );
};
export default MyComponent;

Local provider (Recommended that you set this up)

If you are using a local image provider for your strapi project (which you most likely are when working locally), it is recommended to create your own wrapper or store default config somewhere in lib

Wrapper example

// components/MyImage.tsx
import { NextStrapiImageProps, StrapiImage } from '@oak-digital/next-strapi-image';
import { FC } from 'react';

const MyImage: FC<Omit<NextStrapiImageProps, 'strapiUrl'>> = (props) => {
    return <StrapiImage strapiUrl={process.env.NEXT_PUBLIC_STRAPI_URL} {...props} />;
};
export default MyImage;

Config example

// lib/config/strapi-image.ts
import { NextStrapiImageProps } from '@oak-digital/nextjs-strapi-image';

export const strapiImageConfig = {
    strapiUrl: process.env.NEXT_PUBLIC_STRAPI_URL,
} satisfies Partial<NextStrapiImageProps>;
// components/my-component.tsx
import { StrapiImage } from '@oak-digital/next-strapi-image'
import { strapiImageConfig } from '../lib/config/strapi-image'

const MyComponent = ({ media }) => {
    return (
        <div>
            {/* Component stuff here */}
            <StrapiImage {...strapiImageConfig} media={media} {/* Other next/image props here */} />
        </div>
    )
}
export default MyComponent

Api

<StrapiImage />

| Prop | Type | Default | Required | Description | | --------------- | ------------ | ------- | -------- | --------------------------------------------------------------------------------------------------- | | media | IMedia | - | - [x] | The media received from strapi | | strapiUrl | string | - | - [ ] | The default strapi url for local providers | | fallbackSize | boolean | true | - [ ] | If the width or height from strapi is null, it will use 0 as a fallback to avoid runtime errors | | ...imageProps | ImageProps | - | - [ ] | The rest of the props can be the same as those on next/image |

Testing locally

For testing purposes, there has been added an /example directory, where a strapi instance can be started and nextjs to make sure all the seo fields are correctly added.

Read more

Publishing

pnpm run release