Usage with Static Data
What if I already have my data?
simply have generator function map over exisiting Array
as shown below with JSON
data
- JavaScript
- TypeScript
import { mocq } from "mocq";
import jsonData from './data.json';
const { generate } = mocq({
nodes: {
generator: (i) => jsonData[i],
count: jsonData.length,
}
});
const { data: { nodes } } = generate();
import { mocq, MocQ } from "mocq";
import jsonData from './data.json';
type JsonDataType = {
id: number
name: string
type: string[]
};
const { generate } = mocq({
nodes: {
generator: (i: number) => jsonData[i],
count: jsonData.length,
} as MocQ<JsonDataType>
});
const { data: { nodes } } = generate();