data undefined in React Hook Form inside a NPM input fields

I´m using a npm of inputs plus react hooks but when i submit the data i get undefined values in my console. I tried using the default input tags and works fine, the data i send shows perfectly. Any suggestions? is it possible to work with this NPM and react hook form or should i use the default data (Something that i don´t really like to do)

import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import Nav from "./Navbar";
import Footer from "./Footer";
import { FormField } from 'react-form-input-fields';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useForm } from "react-hook-form";
import { faEye,faEyeSlash } from '@fortawesome/free-solid-svg-icons';
import 'react-form-input-fields/dist/index.css';
function Login() {

  const {register, handleSubmit } = useForm();
  const eye = <FontAwesomeIcon icon={faEye} />
  const closeEye = <FontAwesomeIcon icon={faEyeSlash} />
  const [passwordShown, setPasswordShown] = useState(false);
  let [email, setEmail] = useState("");
  let [password, setPassword] = useState("");

  const togglePasswordVisiblity = () => {
    setPasswordShown(passwordShown ? false : true);
  };

  const onSubmit = (data) => {
    console.log(data)
  }

  return (
    <div className="page-container">
      <div className="content-wrap">
        <Nav />
        <div className="div-login-form">
        <h1 className="title">Login</h1>
        <form className="login-form" onSubmit={handleSubmit(onSubmit)}>
          <FormField
            type="email"
            standard="labeleffect"
            value={email}
            keys={'email'}
            name="email"
            effect={'effect_1'}
            handleOnChange={(value) => setEmail(value)}
            {...register("email")}
            placeholder={'Enter Email'} />
            <div className="input-password">
            <div className="icon-eye"> 
            <i onClick={togglePasswordVisiblity} className="icon"> {passwordShown ? eye : closeEye} </i>
            </div>
            <FormField
            type={passwordShown ? "text" : "password"}
            standard="labeleffect"
            value={password}
            keys={'password'}
            name="password"
            effect={'effect_1'}
            handleOnChange={(value) => setPassword(value)}
            {...register("password")}
            placeholder={'Enter Password'} />
            </div>
            <button className="button-shop" type="submit">
              Log in
            </button>
        </form>
        </div>

      </div>
      <Footer />
    </div>
  );
}

export default Login;

Uncaught Error: Actions must be plain objects. Use custom middleware

The error seems common and when I made some research I saw that it’s mostly due to omission of middlewere (like thunk) or failing to call the dispatch function. Even after trying to put those things in check I keep getting the error

function RegisterScreen({ signup, isAuthenticated }) {

    const [accountCreated, setAccountCreated] = useState(false);
    const [username, setUsername] = useState([])
    const [email, setEmail] = useState([])
    const [password, setPassword] = useState([])
    const [re_password, setRe_password] = useState([])
    const [message, setMessage] = useState('')


    const dispatch = useDispatch()
    const auth = useSelector(state => state.auth)
    const { error, loading } = auth

    const submitHandler = (e) => {
        e.preventDefault();
        if (password !== re_password) {
            setMessage('Both passwords must be the same')
        } else {
            dispatch(signup(username, email, password, re_password));
            setAccountCreated(true);
        }
    }
    
 
    return (
        <Container className='content auth-container'>
            <div className="auth-header text-center mb-4">
                <h2 className="auth-header">Sign Up</h2>
                <p>Add your deatils to sign up</p>
            </div>
            {message && <Message variant='danger'>{message}</Message>}
            {error && <Message variant='danger'>{error}</Message>}
            {loading && <Loader />}
                    <Form className="auth-form" onSubmit={submitHandler}>
                        <Form.Group className="mb-3" controlId='name'>
                            <Form.Control 
                                className="auth-input search-ppty" 
                                required
                                minLength='6'
                                type="name" 
                                placeholder="Username" 
                                value={username}
                                onChange={(e) => setUsername(e.target.value)}
                                />
                        </Form.Group>
                        <Form.Group className="mb-3" controlId='email'>
                            <Form.Control
                                required 
                                className="auth-input search-ppty" 
                                type="email" 
                                placeholder="Email" 
                                value={email}
                                onChange={(e) => setEmail(e.target.value)}
                                
                                />
                        </Form.Group>
                        <Form.Group className="mb-3" controlId="password">
                            <Form.Control 
                                className="auth-input search-ppty" 
                                type="password" 
                                placeholder="Password" 
                                value={password}
                                onChange={(e) => setPassword(e.target.value)}
                                
                                />
                        </Form.Group>
                        <Form.Group className="mb-3" controlId="passwordConfirm">
                            <Form.Control 
                                className="auth-input search-ppty" 
                                type="password" 
                                placeholder="Confirm Password" 
                                value={re_password}
                                onChange={(e) => setRe_password(e.target.value)}
                                />
                        </Form.Group>
                        <Button type="submit" className="auth-button">Sign Up</Button>
                    </Form>
                    <Row className="p-2">
                        <Col>
                            <div className=""> Already have an account? <Link to="/login">Login</Link></div>
                        </Col>
                        <Col>
                            
                        </Col>
                    </Row>
        </Container>
        
    )
}

export default connect(null, {signup}) (RegisterScreen)

Redux store

import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

const middleware = [thunk]

const store = createStore(
    reducer, 
    composeWithDevTools(applyMiddleware(...middleware))
    )

export default store

I have spent several hours still can’t find where the error is coming from in the code. How do I fix it?

panzoom set specific bounds to not show space in container

Currently using timmywils panzoom library: https://github.com/timmywil/panzoom

Im currently trying to build a “map” where you can pan around and click on specific elements. Im currently having some issues with this though.

When panning I dont want to show space thats outside of the bounds if that makes sense.

In the image below, I would imagine the “div.adventure-map” to have a background image.
This would okay to show because the container element behind it is completely covered.
enter image description here

However, this image would NOT be okay because the container element behind it isnt covered completely and would just be black.
enter image description here

I feel like im approaching this problem incorrectly but am having a bit of a brain fart.

Im starting to think maybe just implementing my own drag/pan solution would be better. Would appreciate some guidance/help!

selecting all elements and adding new element after each one

I have some simple vanilla code here. My goal is to grab all the sections, loop through them and after each one insert a new element:

let sectionSign = document.createElement('p');
sectionSign.innerHTML = '&#167;'
sectionSign.style.marginTop = '1rem'

let allSections = document.querySelectorAll('section')

allSections.forEach((section) => {
    section.style.border = '1px solid red'
    section.after(sectionSign)
})

the style.border was just to make sure it selected all the elements that I wanted and it did. However, the sectionSign is only being added after the last section, not after each one. How can I resolve this?

Activate href if elements top equals zero after addClass jQuery

I have a simple menu, everytime i click an element the others fadeOut and the clicked one goes up if it’s not the first element, and after that i activate the href of the link.

To activate the link i need to make sure that the element is in the top of the page, after the addClass slideUpSm the clicked item gets new position top

setTimeout(function() {$('.main-nav li').addClass('slideUpSm')}, 1200);

After that, i can activate the window location, i have tried the hasClass methode and also tried to check if the new position top equals zero, here is my attemt https://jsfiddle.net/bsq3dL4t/

setTimeout(function() {window.location = href}, 100);

Array combinatorics in javascript, It’s wrong?

I have created this script due to the need to perform unique combinations when I receive n number of arrays, it works, however when I want to store in a final array it writes something different. Thank you very much for your help and I hope that the script will be useful to those who need it.

let options = {
            "A": ["A1", "A2", "A3", "A4"],
            "B": ["B1", "B2"],
            "C": ["C1", "C2", "C3", "C4", "C5"],
        };

        let keys = Object.getOwnPropertyNames(options);
        let size = keys.length;

        let final = [];

        function combinate(n, o) {

            for (let i = 0; i < options[keys[n]].length; i++) {

                if (n === (size - 1)) {
                    o = {};
                }

                o[keys[n]] = options[keys[n]][i];

                if ((n - 1) >= 0) {
                    combinate(n - 1, o);
                }

                if (n === 0) {
                    console.log(o);
                    final.push(o);
                }

            }

        }

        if (size > 0) combinate(size - 1, {});

        console.log("-----------------------------------")
        console.log(final);

React: How to unmute html video by custom button

I am working on a project and came across a little issue:
So, i have a video tag:

<video muted autoPlay loop src={video}>

and i just want a single custom button/control to unmute and mute the video.
Am i right when i think of something using reactHooks and something like onClick={(handleChange => ??, or something like this:

    <button onClick={() => toggle(!mute)}>
        {mute ? 'Mute' : 'Unmute'}
    </button>

but i do not really know how to setup the mute function in order to control the video tag.

Can someone help me out?

dotenv file is not recognized by server nodejs

this is my first mern stack project ever and i’m trying to push it to github.
i am using mongoose so i had to hide the login and pwd of my account i looked it up and found the .env solution.
I created a dot env file

Port=5000
CONNECTION_URL=mongodb+srv://[email protected]/++++++?retryWrites=true&w=majority

i ran npm i dot env

then i added import statement :

import dotenv from ‘dotenv’;

and the problem seems to occur here,
i tried :

dotenv.config()
require('dotenv').config();

the code to of my index js if it helps to solve the solution :

const PORT = process.env.PORT|| 5000;

mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() => app.listen(PORT, () => console.log(`Server Running on Port: http://localhost:${PORT}`)))
  .catch((error) => console.log(`${error} did not connect`));

mongoose.set('useFindAndModify', false);

can anyone help me solve this up i would really appreciate it thank you ^^

Time complexity of searching for target value in 2D matrix?

The actual problem is pretty simple, implement an algorithm that returns true if the target value is contained within the matrix. Here are the two solutions I came up with. I’m not sure which one would be preferable? I believe solution 1 is faster since we don’t need to build a new array, however would this be significantly faster?

Solution 1:

var searchMatrix = function(matrix, target) {
    let cols = matrix[0].length;
    let rows = matrix.length;
    let left = 0; 
    let right = cols*rows - 1;
    
    while(left <= right) {
        let midIndex = left + Math.floor((right-left)/2);
        let midValue = matrix[Math.floor(midIndex/cols)][Math.floor(midIndex%cols)];
        console.log(midValue);
        if(midValue === target) {
            return true;
        }
        else if(midValue < target) {
            left = midIndex + 1;
        } else {
            right = midIndex - 1;
        }
    }
    return false;
};

Solution 2:

var searchMatrix = function(matrix, target) {
    let arr = []
    for(let row of matrix) {
        arr = [...arr,...row];
    }
    let left = 0;
    let right = arr.length - 1;
    
    while(left <= right) {
        let middle = left + Math.floor((right-left)/2);
        if(arr[middle] === target) {
            return true;
        } else if(arr[middle] < target) {
            left = middle + 1;
        } else {
            right = middle - 1;
        }
    }
        
    return false;
};

Based on my understanding, the main step we’re adding is converting the matrix into a regular Array. Would this make the algorithm O(n) since we have to add every element into the new array?

For solution 1, we don’t have to create a new array so we’d have constant space correct?
I’m not particularly sure how to explain the first solution is preferable in terms of time/space.

How to create a new table inserting a variable into .doc()

I’ve created a SignIn page that allocates its data on variables using document.getElementByClassName.
So, I’m trying to create a new document on Firebase using the person’s name, stored on a variable (which could bring some problems) using — .doc(variableHere) — but I didn’t manage to find a way.

let newUserPrimeiroNome = document.getElementsByClassName("primeiroNome");
let newUserSobrenome = document.getElementsByClassName("ultimoNome");
let newUserEmail = document.getElementsByClassName("email");
let newUserPassword = document.getElementsByClassName("senha");

let btn = document.getElementById("btn");
btn.addEventListener("click", criaNovoUsuario);

function criaNovoUsuario() {
    db.collection("loginsSecretaria").doc(newUserPrimeiroNome) // <- error here
    .add({
        primeiroNome: newUserPrimeiroNome[0].value,
        ultimoNome: newUserSobrenome[0].value,
        email: newUserEmail[0].value,
        senha: newUserPassword[0].value
    }).then(() => {
        console.log("Documento inserido com sucesso");
    }).catch((error) => {
        console.log("Erro ao inserir documento: ", error);
    });

ps.: I’m sorry if I didn’t express myself in very clear way

deploying puppeteer automation for a bill summary website

I wrote a simple puppeteer code to log into websites and retrieve the amount due. I would like to build this into a website where my roommates can log in to view the breakdown of total due and have a cash app QR code embedded. I am hoping to turn this into a showcase project with responsive React and Firebase Auth.

This code file currently has login id and password written in and for obvious reasons I did not upload this to github. From what I read even private github repositories are not truly private?

How do I go about deploying this project while keeping the login info secure? I’ve been using cloudflare pages and it looks like only option for deployment is for me to create a git repository. Thank you.

How to force render same id with same data?

I have some card components (soldItems, createdItems) with same data, so this mean created items and sold items both are owned by creator and displayed on his profile, i want to show soldItem if it solded and don’t show createdItem if it solded …

Example:

SoldItem.filter((sold)=>{
CreatedItem.filter((created)=>{
   if(sold.id === created.id){
   console.log("matched");
   // In case its matched i want to show one of them not both
}else{
   console.log("not matched")
}
})
})

How to do conditional defining of key in an object in JS?

Suppose I want to create an object with keys as USD and non-USD. Like Below:

    let obj = {
                USD: {
                   sourceValue: 100
                   destinationValue: 10
                }, 
                non-USD: {
                  sourceValue: 10
                   destinationValue: 100
                }
              }

Except here, instead of non-USD, I should be able to pass any currency, like SGD or HKD and I should get result of non-USD currency.

so, if I wrote obj[currency].sourceValue and currency=HKD then I should get 10

I don’t want to use obj[1].sourceValue as currency value is dynamic.

Also, I don’t want to use if(currency!='USD') index=1 and then obj[index].sourceValue

So, my question is, what should I write at place of non-USD while defining object? I checked computation names, but I am not sure, how will I pass long currency array as key name and filter USD out of it?