javascript - use an array from another js file in nextjs page

Solution:

I recommend using getServerSideProps

import { items } from "../../public/assets/ArticlesList.js"; const ArticlePage = ({ data }) => { return ( <> <Head> <title> {data.title} </title> </Head> <div> .... </div> </> ); } export async function getServerSideProps(context) { const { id } = context.query; const data = items[id]; return { props: { data } } } export default ArticlePage;

Solution:

Make a common component like below: and import on top of the page. Then you won't have any problem of undefined data.

import Head from 'next/head'; const MetaData = (props) => { const title = props.title || ''; const description = props.description || ''; const keywords = props.keywords || ''; const image = props.image || ''; return ( <Head> <title>{title}</title> <meta name="description" content={description} /> <meta name="og:description" content={description} /> <meta name="twitter:description" content={description} /> <meta name="twitter:site" content="" /> <meta name="twitter:card" content="summary" /> <meta name="twitter:title" content={title} /> <meta name="og:site_name" content="" /> <meta name="og:title" content={title} /> <meta name="keywords" content={keywords} /> <meta name="og:image" content={image} /> </Head> ); }; export default MetaData;

SEO Tools


Crop Image

Crop image Online

Crop Image
Image Resizer

Image resizer Online

Image Resizer
Exif Online

Exif Online

Exif Online
JPG to PNG

Convert JPG to PNG

JPG to PNG

PNG to JPG

Convert PNG to JPG online

PNG to JPG
Server status

Check Server Status - Check sites HTTP status codes

Server status
Site charset

Check website Charset Online. Find out the encoding of your site online.

Site charset
DA Rank

Domain Authority by MOZ. Find out domain authority for free. Site analysis, seo audit.

DA Rank

HTML editor

Free HTML Editor

HTML editor
.htpasswd generator

Htpasswd Generator – Create htpasswd

.htpasswd generator
Joomla theme detector

With supporting text below as a natural lead-in to additional content.

Joomla theme detector
Mass check domains

Mass checking domains on availability

Mass check domains

md5 generator

MD5 Generator

md5 generator
RGB to HEX

RGB to HEX converter

RGB to HEX
robots.txt generator

Robots.txt generator

robots.txt generator
URL encoder/decoder

URL Encoder/Decoder Online

URL encoder/decoder

URL shortener

URL shortener

URL shortener
UTM generator

UTM Tag Generator For Google Adwords and Facebook

UTM generator
Site link count

Website Link Count Checker

Site link count
Site page size

See your page size online

Site page size

What is my browser

What is my browser Online

What is my browser
What is my IP

My IP Online

What is my IP
Words counter

Word counter online

Words counter
WP theme detector

Find out online which WordPress template is installed on the site.

WP theme detector

XML sitemap generator

XML sitemap generator

XML sitemap generator
XML sitemap validator

Check online if the sitemap was made correctly XML for Google.

XML sitemap validator