Home > Blockchain >  Is there a new form of the contextualCard feature in faker.js
Is there a new form of the contextualCard feature in faker.js

Time:07-19

I haven't used faker since the wipe and am not familiar with the current form of it. Is there a function similar to the contextual card function in the new version? or a function to create fake usernames? my current code looks like this

useEffect(() => {
  const suggestions = [...Array(20)].map((_, i) =>({
    ...faker.helpers.contextualCard(), 
    id:i,
  }));

  console.log(suggestions);
}, []);

Anything helps. Thanks!

CodePudding user response:

Wow, that's from Sonny Sangha Instagram's video? I'm with the same problem here and after searching some issues in Faker Github, it looks that they turned it deprecated, so you should make your own method to get your specifics objects. I saw an example on their readme:

import { faker } from '@faker-js/faker';
// import { faker } from '@faker-js/faker/locale/de';

export const USERS: User[] = [];

export function createRandomUser(): User {
  return {
    userId: faker.datatype.uuid(),
    username: faker.internet.userName(),
    email: faker.internet.email(),
    avatar: faker.image.avatar(),
    password: faker.internet.password(),
    birthdate: faker.date.birthdate(),
    registeredAt: faker.date.past(),
  };
}

Array.from({ length: 10 }).forEach(() => {
  USERS.push(createRandomUser());
});

CodePudding user response:

Thnx for your answer Matt! the easier operation for me was to download the older version of faker using npm install [email protected].

  • Related