React MUI 4 SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading ‘value’)

This error happens when you provide an empty array as options.

The error log:

SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    at SelectInput.js:340:1
    at Array.map (<anonymous>)
    at SelectInput.js:339:1
    at invokePassiveEffectCreate (react-dom.development.js:23487:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at performSyncWorkOnRoot (react-dom.development.js:22269:1)
    at react-dom.development.js:11327:1
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322:1)
    at flushSyncCallbackQueue (react-dom.development.js:11309:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23620:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at react-dom.development.js:23324:1
    at workLoop (scheduler.development.js:417:1)
    at flushWork (scheduler.development.js:390:1)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:157:1)

i want to check if current user is following other user

i want to check if current user is following other use lets say check if user A is following user B.

User Model:-

const UserSchema = new Schema({
    email: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        validate: (value) => {
            if (!validator.isEmail(value)) {
                throw new Error('Invalid email address.');
            }
        }
    },
    fullName: {
        required: true,
        type: String,
    },
    username: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        minlength: 3,
    },
    password: {
        type: String,
        minlength: 8,
    },
    avatar: String,
    bio: {
        type: String,
        default: null,
        maxlength:300,
    },
    location: {
        type: String,
        default: 'Bangalore'
    },
    website: {
        type: String,
        default: null,
    },
    joindate: {
        type: Date,
        default: new Date()
    },
    isVerified:{
        type:Boolean,
        default:false,
    }

})

const UserModel = mongoose.model('User', UserSchema);
module.exports = UserModel;

Followings Model:-


const FollowingsSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followings: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followings = mongoose.model('Followings', FollowingsSchema);
module.exports = Followings;

Followers Model:-



const FollowersSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followers: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followers = mongoose.model('Followers', FollowersSchema);
module.exports = Followers;

currently i was able to achieve this by iterating through each follower and check if user exist in that user followers list.
i want to achieve this with mongodb aggregation ,im new to mongob

WebBluetooth API writeValueWithoutResponse does not seem to have an effect on connected device

I am trying to connect to a Buwizz V2 hub (and start a motor) via BLE on a windows machine via WebBluetooth in Google Chrome Browser.

The API for the Buwizz is https://buwizz.com/BuWizz_2.0_API_1.3_web.pdf

The result of my code is

ble.html:21 discoverDevicesOrDisconnect
ble.html:31 discoverDevices
ble.html:40 > Name: BuWizz
ble.html:41 > Id: NtY+vKj4GR1vb/VowbQdJw==
ble.html:42 > Connected: false
ble.html:44 BluetoothDevice {id: ‘NtY+vKj4GR1vb/VowbQdJw==’, name: ‘BuWizz’, gatt: BluetoothRemoteGATTServer, ongattserverdisconnected: null, watchingAdvertisements: false, …}
ble.html:74 connecting
ble.html:77 Connected to NtY+vKj4GR1vb/VowbQdJw==
ble.html:78 connected=true
ble.html:96 discoverSvcsAndChars server=[object BluetoothRemoteGATTServer]
ble.html:102 Got 1 services
ble.html:109 Getting Characteristics for service 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:111 > Service: 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:117 >> Characteristic: 000092d1-0000-1000-8000-00805f9b34fb
ble.html:125 FINISHED DISCOVERY
ble.html:54 Try to startMotor
ble.html:55 Will send command to Characteristic:000092d1-0000-1000-8000-00805f9b34fb
ble.html:56 Characteristic has writeWithoutResponse ability:true
ble.html:60 Motor command ->16,127,127,127,127,0

So I can discover and connect to the device, find the Service 4e050000-74fb-4481-88b3-9919b1676e93, find the characteristic 000092d1-0000-1000-8000-00805f9b34fb and check that is has writeWithoutResponse.

Since the motor is not running after sending the command, I have obviously made something wrong.

And I guess that it is somewhere around here:

  console.log("Try to startMotor");
        console.log("Will send command to Characteristic:" + motor_characteristic.uuid);
        console.log("Characteristic has writeWithoutResponse ability:" + motor_characteristic.properties.writeWithoutResponse);

        let full_ahead_command_data = new Uint8Array;
        full_ahead_command_data =  Uint8Array.of(0x10, 0x7F, 0x7F, 0x7F, 0x7F, 0x00);
        console.log('Motor command ->' + full_ahead_command_data);

        motor_characteristic.writeValueWithoutResponse(full_ahead_command_data.buffer)
            .then(_ => { })
            .catch(error => {
                console.log('Error: ' + error);
                alert('Error: ' + error);
                return;
            });

I checked the hub and motor with the official app. Both are working fine, so i would appreciate hints where I made something wrong or made a wrong assumption.

array updates in delay on checkbox click

im trying to create an array of user premissions, which can be controled by a set of checkboxes.
when i check a box and console.log() the array it looks just fine with all the premissions i checked, but when i uncheck the box, the console.log() returns the previus array value and it will be ubdated only on the next click

  const [prems, setPrems] = useState([]);

  const handleCheckbox = (e) => {
    let arr = prems
    if (e.target.checked) {
      arr.push(e.target.value)
      setPrems(arr)
      console.log(prems) //shwos the array with all the checked values
    } else {
      let newArr = arr.filter((item) => {
        return item !== e.target.value
      })
      setPrems(newArr)
      console.log(prems) //shows the array still with the value i unchecked
    }
  };

the event on the checkboxes is onChange and it works the same with onClick

How to convert a numeric property of an object in a class to a number and add with other numbers in JS?

I want to add 2 values together at the method in the customer class. one of them is a number and the other is an object property stored in a new class, the send method(a-b) works well, but the receive method(a+b) doesn’t work as a number because it’s an object and it is like a string in js, what is the solution?

export class Customer {
  constructor(name, password, balance) {
    {
      this.name = name;
      this.password = password;
      this.balance = balance;
    }

    this.send = function (amount) {
      return (this.balance -= amount);
    };
    this.receive = function (amount) {
      return (this.balance += amount);
    };
  }
}

export let student = new Customer("alex", "alex", 200);
export let victim1 = new Customer("tom", "cat", 1000);
export let victim2 = new Customer("jerry", "mous", 500);

chart.js disable opacity-animation for tooltip

I have a chart, in which I draw some metadata in animation.onComplete:

animation: {
  onComplete: ChartHelper.barChartDrawMetadata(28, 2)
}

When hovering over the chart, a tooltip with extra information shows. But the opacity of this tooltip is animated, 400ms. (I found this in chart.esm.js).

During the tooltip’s animation, the drawn metadata is removed, and redraws after the tooltip’s animation has completed.

I would like to make the animationDuration of the tooltip 0, so that the metadata redraws immediately when the tooltip shows, and is not gone for 400ms at a time.
How would I go about this, if it is even possible?

I tried many things, like setting plugins.tooltip.animation.duration = 0, or plugins.tooltip.animationDuration = 0, etc.

Now the only way I see is editing the value that is set in chart.esm.js, but I don’t see any way to access/override this value.

animations: {
  numbers: {
    type: 'number',
    properties: ['x', 'y', 'width', 'height', 'caretX', 'caretY'],
  },
  opacity: {
    easing: 'linear',
    duration: 200
  }
}

Is there any documented way to disable the tooltip animation, or not hide the metadata?

Eslint: Manually control absolute and relative imports

I’d like to have a eslint rule which will make to have relative import paths for everything that is imported from inside of the directory and absolute paths for everything that is imported from outside of the directory.

Example: This is my file structure


/Dashboard
    /components
        /Component1.tsx
/Home
    /components
        /Component2.tsx
        /Component3.tsx
    /utils
        /util1.ts
style.ts

I want to have relative imports inside of my Home directory and absolute imports for everything that imported from outside of my Home directory.

My Component2.tsx’s imports should look like this

import Component3 from './Component3'
import util1 from './../util1'
import FlexBox from './../../styled'
import Component1 from 'Dashboard/components/component1' // this should be absolute


Migrate large json file into Mongodb using nodejs

I’m using nodejs to migrate data into mongodb, the json file which i’m trying to migrate is too large, when I try to migrate just some data (about 8000 docs), it works, otherwise I’m getting this issue :

MongooseError: Operation `products.insertOne()` buffering timed out after 10000ms

at Timeout.<anonymous> (migration- 
modulenode_modulesmongooselibdriversnode-mongodb-nativecollection.js:148:23)

at listOnTimeout (internal/timers.js:557:17)

at processTimers (internal/timers.js:500:7)

MongooseError: Operation `products.insertOne()` buffering timed out after 10000ms

 at Timeout.<anonymous> (migration- 
modulenode_modulesmongooselibdriversnode-mongodb-nativecollection.js:148:23)

at listOnTimeout (internal/timers.js:557:17)

at processTimers (internal/timers.js:500:7)

the script :

/** @format */
fs = require('fs')
var mongoose = require('mongoose')
 mongoose.connect('mongodb://host')
 mongoose.Promise = global.Promise
 var schema = new mongoose.Schema({
 //some fields
  })
  var d = fs.readFileSync('./data/file.json', 'utf8', (err, data) => {
   if (err) throw err
   return d
   })
  var e = JSON.parse(d)
  var Product = mongoose.model('product', schema)
  //console.log(e)
  for (var i = 0; i < e.length; i++) {
   // data process
   // another data process
  var product = new Product(e[i])
  product.save(function (err) {
  if (err) return console.log(err)
  })
 }
 e.length === i ? console.log('Migration Done successfully') : ''

any solution to get ride of this problem please ?

My js code is not working can anyone find error

There are many <li/> with class name list and one having active too and I wanna give active class name to <li/> on clicking

const list = document.querySelectorAll('.list');

function activeLink(){
    list.forEach((element) =>
      element.classList.remove('active')
    );
    this.classList.add('active')
}

list.forEach((element) => 
  element.addEventListener('click',activeLink)
)

how do I load more on one image at once from this API, and display it in a grid?

I essentially want the page to initially load with a total of 9 images from this api. If I add another image, and retrieve it on page load, it displays a duplicate, and only when I fetch the api again, does the api make a random call, and load a new image.

Right now, on page load, one image is displayed, with text retrieved from the json object and stored in a parapragh.

My end goal is to have the page load with 9 different images of the dogs, and have a button that fetches the json data for each unique dog, so all images will be linked to a unique button.

I’m having trouble wrapping my head around a few of the concepts, and React is very new to me.

App.js

import './App.css';
import './Dog.js';
import FetchAPI from './FetchAPI';




function DogApp() {

  return (
    <div className="DogApp">
     <FetchAPI />
    </div>
  );
}

export default DogApp;

FetchAPI.js

import React, { useState, useEffect } from 'react'


const FetchAPI = () => {

    const [data, setData] = useState([]);

    const apiGet = () => {
        const API_KEY = "";
        fetch(`https://api.thedogapi.com/v1/images/search?API_KEY=${API_KEY}`)
            .then((response) => response.json())
            .then((json) => {
                console.log(json);
                //setData([...data,json]); if json is single object
                setData([...data, ...json]); // if json is array of one object then use this line
            });
    };


    useEffect(() => {           //call data when pagee refreshes/initially loads 
        apiGet();


    }, []);

    return (
        <div>
            {data.map((item) => (
                <div class="dog">
                    <img src={item.url}></img>
                    <button onClick={apiGet}>Fetch API</button>
                </div>
            ))}
            {data.map((item) => (
                <p>{JSON.stringify(item.breeds)}</p>
            ))}


            {/*<pre>{JSON.stringify(data, null, 2)}</pre> */}
            <br />


        </div>

    )
}

export default FetchAPI;

Change background-position with scroll and mouse whell up/down with animeJS

I want to change the background-position when scrolling, when scrolling up, a reverse is done, when scrolling down, the usual animation is played. I need full paste scrolling. I need to define scrolling with scroll and mouse wheel. At the moment, I only have a scroll, but for some reason the animation only happens when the scroll is completed and not at the time of the scroll.

CodeSandbox