How to change displayed text in react component?

I installed react-mailchimp-subscribe and I want to change text button because my website is not written in English.
i putted this component into div className="pokemon" to have access to him like .pokemon > div > button and could have change styles. Now I want to change text.
I try to acces to him by using

useEffect(() = > {
document.addEventListener("load", function(){
(".pokemon>div>button").innerHtml("Wyślij")
}); }, [])

but I guess in my function is too many errors that it actually work.

html + javascript scroll detection not working

I cannot seem to get scroll event to work for this layout. I am stuck and I was wondering if you guys can help me out. What I am trying to do is to detect when the content div, which has id=”myContent”, is scrolling. What am I doing wrong?

Thanks in advance.

<!DOCTYPE html>
<html>
<head>

<script>    

    window.onscroll = function() {scrollFunction()};

    function scrollFunction() {
        console.log("scrollFunction");
    }
    
    console.log(document.getElementById("myContent")); //dont know why it cannot find this arrrgghhh !!!

</script>
    
</head>
<body style="width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    position: absolute;">

    <!--container-->
    <div style="border: 1px solid red;
        width: 100%;
        height: 100%;
        position: fixed;
        overflow: auto;
        overflow-x: hidden;">
            
        <!--header-->       
        <div style="border: 1px solid green;
            width: 100%;
            height: 75px;
            top: 0;
            position: sticky;
            margin: 0 auto;
            align-items: center;"> 
        </div>
        
        <!--content-->
        <div id="myContent" 
            onscroll="scrollFunction();"            
            style="border: 1px solid blue; 
                width: 100%;
                height: auto;
                margin: 0 auto;">   
                
            <!--content 1-->                    
            <div style="width: 100%; height: 1000px;">
            
            </div>          
        </div>
        
        <!--footer-->
        <div style="border: 1px solid pink;     
            width: 100%;
            height: 150px;
            margin: 0 auto;">   
        </div>          
    </div>  
</body> 

Any help is appreciated.
Thanks in advance

Best regards

Javascript shorten without cutting and exclude too long words one line

The following Javascript process the string in step-by-step order – first REPLACE shorten the string to total 60 chars without cutting words – then SPLIT by words and last filter out words more than 30 chars

var wordsplit = word.replace(/^(.{60}[^s]*).*/, "$1").split(' ').filter(function(token){ return token.length < 30});

so everything is ok, but when I change the order of actions as below (first split and filter out words more than 30 – and last – shorten)

var wordsplit = word.split(' ').filter(function(token){ return token.length < 30}).replace(/^(.{60}[^s]*).*/, "$1");

such a sequence does not work.

Thx for an opinion what’s wrong with

var wordsplit = word.split(' ').filter(function(token){ return token.length < 30}).replace(/^(.{60}[^s]*).*/, "$1");

as the first variant works.

Path browersify resolve method

I’m using the path-browserify npm package, all the other methods are fine, like basename, parse, and format. However whenever I try to import and use the resolve method I get the following error:

Uncaught ReferenceError: process is not defined

node js logout function problem in when deploy vercel

Hello ı have website created html,css and nodejs, before deploy vercel ı deployed my apps to heroku and localhost and tried to run and everything works perfectly , but when ı deploy vercel“ my app and try to logout in node js my website is just refresh the page sometimes logout but mostly refresh the page and not delete jwt token and not logout
Node-js

const logout = async(req,res,next) => {
  try {
     res.clearCookie("jwt")
     await req.user.save()
  } catch (error) {
    res.json(error)
  }
}

and my login route

const loginUser = async(req,res,next) => {
 
  console.log(req.body)
  const {nickname, password,phone} = req.body
  console.log(phone)
  const user = await User.findOne({
    nickname,
    

  })
  console.log(user)
  if(!user) {
    return res.json({status: 'error', error: 'Invalid username/password'})
  } 
 
  if(await bcrypt.compare(password,user.password)) {

    const token = jwt.sign({
      id:user._id,
      nickname:user.nickname,
      role:user.role
    },
      process.env.JWT_SECRET
    )

    var role = user.role
    if(user && role == "await") {
      return res.json({status: 'error',error: 'Hesabınız onay aşamasında'})
    }
   
    res.cookie('jwt', token, { expires: new Date(Date.now() + 3000000), httpOnly: true })
    
    
    return res.json({status: 'ok', data:token})

  }
  return res.json({status: 'error', error: 'Böyle bir kullanıcı adı/şifre bulunamadı!'})
}

this keyword not working inside setTimeout in javascript?

Learning javascript.
Why first code is giving error where as second is not?
In first code why this is being considered as window{} where as in second it is doing what it meant to do?

1st

const tahoe = {
        mountains: ["Freel", "Rose", "Tallac", "Rubicon", "Silver"],
        print: function(delay = 1000) {
            setTimeout(function() {
                console.log(this.mountains.join('  '));
            }, delay);
        }
    };
    tahoe.print();

2nd

const tahoe = {
            mountains: ["Freel", "Rose", "Tallac", "Rubicon", "Silver"],
            print: function(delay = 1000) {
                setTimeout(()=> {
                    console.log(this.mountains.join('  '));
                }, delay);
            }
        };
        tahoe.print();

make unit convert on javascript

i need to create unit converter. Default application must convert m,cm,in,ft beetwen each other. It is also necessary to implement the ability to expand the list of supported units
by setting conversion rules via JSON file. JSON file format – on
your discretion. As an example, extend your application by adding to the file
values for millimeters (mm), yards (yd), and kilometers (km).

An object in JSON format containing the distance specified for conversion (distance) from
value (value) and scale (unit), as well as the designation of the unit for the scale to which
must be converted (convert_to). For example:
{“distance”: {“unit”: “m”, “value”: 0.5}, “convert_to”: “ft”}

An object in JSON format containing the received distance value, rounded up to
hundredths, as well as the designation of the corresponding unit of measure, for example:
{“unit”: “ft”, “value”: 1.64}

Thank for help.

Use JS Modules to return elements vs. return a function which created the elements

I’m doing The Odin Project and my current project involves adding elements to the HTML using JS. The webpage should be tabbed with each tab being drawn using a separate JS module. In the instructions here, they say

Each module will export a function that creates a div element, adds the appropriate content and styles to that element and then appends it to the DOM.

As I worked through the project, I felt that I could instead create the elements in the module and have the module export the elements themselves (instead of a function) which are then appended in the main script.

My approach (simplified):

// menu.js
const menu = document.createElement('div');
/* add children to menu */

export default menu;
// index.js
import menu from './menu.js'

const content = document.querySelector('#content')

content.appendChild(menu)

Compared to the suggestion in the project, what are the advantages and disadvantages of each method?

Also if you use a function as suggested, does that mean that we would need to pass the parent element into the function since its not initialized within the module?

Javascript: How to prevent adding div on document.execcommand(“insertText”) on `contentEditable` element?

Is there a way to prevent auto adding div or any other tag when executing insertText on contentEditable div?

For instance I want to copy and paste a paragraph containing many newLine character:

Lorem ipsum dolor sit amet, 
consectetur adipiscing elit, 
sed do eiusmod tempor 
incididunt

it has 4 lines. When I copy and paste it into my contentEditable div, it became:

<div>Lorem ipsum dolor sit amet,</div>
<div>consectetur adipiscing elit,</div>
<div>sed do eiusmod tempor</div>
<div>incididunt</div>

I works fine with insertHTML, but the problem is that sometimes I want to copy and paste HTML elements too like:

<h1>Title</h1>
<p>Hello world</p>
<div>Horayy</div>

I do not want to create html elements inside my contentEditable div.

How can I achieve this?


NOTE

I can prevent adding div if I input enter key manually, but this case is different, I need to prevent it for copied text.

This is what I have done:

  const pastePlainText = useCallback((e: ClipboardEvent) => {
    e.preventDefault();

    if (e && e.clipboardData) {
      var text = e.clipboardData.getData('text/plain');
      setPreventAddingDivOnEnter(true);
      document.execCommand("insertText", false, text);
    }
  }, []);

Is there a way to paginate through populated documents using mongoose-paginate-v2?

I’ve got User and Post models. User.favPosts is an array of refs to the Post model. I’m calling paginate like this:

options = { populate: {path: 'favPosts'} };
const result = await User.paginate({}, options)

And the result is a user document with populated posts:

{
  "docs": [
    {
      "_id": "6299ffa5c2ca4cdeebd1f513",
      "name": "user",
      "email": "[email protected]",
      "favPosts": [
        {
          "_id": "629b299897f46f31761ad7a7",
          "title": "Available Test 5",
          "description": "Lorem ipsum dolor sit"
        },
        {
          "_id": "629b1edf108e765744d2560d",
          "title": "Available Test 4",
          "description": "Lorem ipsum dolor sit"
        },
        {
          "_id": "629b1c0027bf0eb197c057dd",
          "title": "Available Test 4",
          "description": "Lorem ipsum dolor sit"
        }
      ]
    }
  ],
  "totalDocs": 1,
  "offset": 0,
  "limit": 10,
  "totalPages": 1,
  "page": 1,
  "pagingCounter": 1,
  "hasPrevPage": false,
  "hasNextPage": false,
  "prevPage": null,
  "nextPage": null
}

So I’m getting the pagination of users. But I want to get pagination of populated documents (posts), so I could get the amount of these, page counting, etc. So I want the result to look like this:

{
  "docs": [
    {
      "_id": "629b299897f46f31761ad7a7",
      "title": "Available Test 5",
      "description": "Lorem ipsum dolor sit"
    },
    {
      "_id": "629b1edf108e765744d2560d",
      "title": "Available Test 4",
      "description": "Lorem ipsum dolor sit"
    },
    {
      "_id": "629b1c0027bf0eb197c057dd",
      "title": "Available Test 4",
      "description": "Lorem ipsum dolor sit"
    }
  ],
  "totalDocs": 3,
  "offset": 0,
  "limit": 10,
  "totalPages": 1,
  "page": 1,
  "pagingCounter": 1,
  "hasPrevPage": false,
  "hasNextPage": false,
  "prevPage": null,
  "nextPage": null
}

Can somebody tell me, is it possible to do such a thing via the mongoose-paginate-v2?