I am using faker in order to make array of random objects, like this:
{
"image": faker.random.arrayElement([
faker.image.nature(),
faker.image.city(),
faker.image.food()
]),
"price": faker.random.number({ min: 20, max: 300 }),
"beds": faker.random.number({ min: 1, max: 15 }),
"type": faker.random.arrayElement([
"Entire home",
"Private room",
"Shared room"
])
}
Actully what happens when making 12 elements like this - all the data is random but not the image, that is the same in every load.
Every refresh there are other photoes, but all the elements in array constains the same image.
What shall I do?
I am using faker in order to make array of random objects, like this:
{
"image": faker.random.arrayElement([
faker.image.nature(),
faker.image.city(),
faker.image.food()
]),
"price": faker.random.number({ min: 20, max: 300 }),
"beds": faker.random.number({ min: 1, max: 15 }),
"type": faker.random.arrayElement([
"Entire home",
"Private room",
"Shared room"
])
}
Actully what happens when making 12 elements like this - all the data is random but not the image, that is the same in every load.
Every refresh there are other photoes, but all the elements in array constains the same image.
What shall I do?
Share Improve this question edited Oct 18, 2017 at 7:33 Orlandster 4,8584 gold badges34 silver badges45 bronze badges asked Oct 18, 2017 at 7:12 user1452221user1452221 1242 silver badges9 bronze badges2 Answers
Reset to default 11To be precise, faker.js is returning the same url, e.g. http://lorempixel./640/480/nature
for faker.image.nature()
call because it's the lorempixel. service that returns random images on request.
If you're rather referring to seeing exactly the same image then this might be related to your browser caching responses (if so, then try disabling cache during development or adding a random query string to the image, e.g. 'image': `${faker.image.nature()}?random=${Date.now()}`
).
So to answer your question - you don't have to do anything. You'll get random images eventually (on request to lorempixel.).
Looked for the same. Found this in the docs.
faker.image.nature(width, height, randomize)
Parameters
| Name | Type | Default |
|------------|-------|---------|
| width? |number | 640 |
| height? |number | 480 |
| randomize? |boolean| false |
Source: https://fakerjs.dev/api/image.html#nature