Skip to content

Instantly share code, notes, and snippets.

const mongoose = require("mongoose");
const Joi = require("joi");
const Schema = mongoose.Schema;
const PostSchema = new Schema({
title: {
type: String,
required: true,
},
const mongoose = require("mongoose");
const Joi = require("joi");
const Schema = mongoose.Schema;
const UserSchema = new Schema({
name: {
type: String,
required: true,
},
mongoose
.connect(
"<database connection string>",
{ useNewUrlParser: true, useUnifiedTopology: true }
)
.then((result) => {
server.listen(port);
server.on("listening", onListening);
})
.catch((err) => {
import { useState, useEffect } from "react";
import useInfiniteScroll from "./useInfiniteScroll";
import axios from "axios";
const App = () => {
//we change here
const [Items, setItems] = useState([]);
const [isFetching, setIsFetching] = useState(false);
//setting tha initial page
const [page, setPage] = useState(0);
const express = require('express');
const router = express.Router();
const usersController = require('../controllers/usersController');
router.get('/users', usersController.getAllUsers);
module.exports = router;
//Import the User model from the Sequelize models
const { User } = require('../models');
//setting up number of items to be fetched per page
const getPagination = (_page, _limit) => {
const limit = _limit ? +_limit : 20;
const offset = _page ? _page * limit : 0;
return { limit, offset };
};
'use strict';
const faker = require('faker');
const users = [...Array(200)].map((user) => (
{
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: faker.internet.email(),
gender: faker.name.gender(),
password: faker.internet.password(8),
import { useRef, useCallback } from "react";
const useInfiniteScroll = (callback, isFetching) => {
//here we use useRef to store a DOM node and the returned object will persist regardless of re-renders
const observer = useRef();
//useCallback takes a callback argument and an array dependency list and returns a memoized callback
//which is guaranteed to have the same reference
const lastElementRef = useCallback(
(node) => {
//App.js
import { useState, useEffect } from "react";
import useInfiniteScroll from "./useInfiniteScroll";
import axios from "axios";
const App = () => {
//we change here
const [Items, setItems] = useState([]);
const [isFetching, setIsFetching] = useState(false);
//useInfiniteScroll.js
import { useRef, useCallback } from "react";
const useInfiniteScroll = (callback, isFetching) => {
//here we use useRef to store a DOM node and the returned object will persist regardless of re-renders
const observer = useRef();
//useCallback takes a callback argument and an array dependency list and returns a memoized callback
//which is guaranteed to have the same reference