Only one element is added to the array

The code is supposed to add 6 random elements to an array from another array, but for some reason it only adds it once
`

  let [cubs, setcubs] = useState([
    {id:1,title:1, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/1.png"},
    {id:2,title:2, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/2.png"},
    {id:3,title:3, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/3.png"},
    {id:4,title:4, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/4.png"},
    {id:5,title:5, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/5.png"},
    {id:6,title:6, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/6.png"},
  ])
  
  let [cubikinapole, setcubikinapole] = useState([

  ])
  
  function sheker(){
    for(let i=0;i<6;i++){
      let randomcub = Math.floor(Math.random() * (6 - 0) + 0)
      let obj = {
        id: new Date().valueOf(),
        title: cubs[randomcub].title,
        img: cubs[randomcub].img
      }
      setcubikinapole([...cubikinapole, obj])
    }
    }

`

Tried the push method but it throws errors

SSE and EventEmitter in NestJS – How to use observables

I want to omit an event that happens in the backend and show it in the frontend. I dont need sockets here because its a one way communication. So I want to try to push the event thats omitted towards the frontend using SSE (Server sent events) in nestjs.
Now the setup is pretty simple according to the docs:

@Sse('sse')
sse(): Observable<MessageEvent> {
  return interval(1000).pipe(map((_) => ({ data: { hello: 'world' } })));
}

This is all fine and dandy, and it works. However, this should now just push the “event” thats happening in the backend, instead of using interval etc.

Here is my current setup:

@Injectable()
export class StocksService {
  public stocks: Stock[] = [
    {
      id: 1,
      symbol: 'Stock #1',
      bid: 500,
      ask: 500,
    }
  ];

  constructor(private eventEmitter: EventEmitter2) {}

  create(createStockDto: CreateStockDto) {
    const stock = {
      id: this.stocks.length + 1,
      ...createStockDto,
    };
    this.stocks.push(stock);

    const stockCreatedEvent = new StockCreatedEvent();
    stockCreatedEvent.symbol = stock.symbol;
    stockCreatedEvent.ask = stock.ask;
    stockCreatedEvent.bid = stock.bid;

    this.eventEmitter.emit('stock.created', stockCreatedEvent);

    return stock;
  }
}

Now this.eventEmitter.emit('stock.created', stockCreatedEvent); emits the event and I can console log it using a small listener, and see it just fine:

@Injectable()
export class StockCreatedListener {
  @OnEvent('stock.created')
  handleStockCreatedEvent(event: StockCreatedEvent) {
    console.log(event);
  }
}

So now, whenever I hit the service with Postman and create a Stock entry, it will console log the event, which is great! Now I want this data pushed towards the frontend using SSE.

However, after digging through the RxJS docs, I am not sure I understand how I am supposed to connect these two.
I know I need to make an Observable, which I tried with:

  @Sse('sse')
  @OnEvent('stock.created')
  sse(event: StockCreatedEvent): Observable<MessageEvent> {
    const obj = of(event);
    return obj.pipe(map((_) => ({ data: event})));
  }

However, even if i go to the url http://localhost:3000/sse it will not do anything, even not console logging or returning any stream.
Do i need an observable here.. or a subject?

Please help a brother out. Here is also the repo, if you need to look at it a bit more specifically

Why is my chrome extension not returning/scraping any emails?

So i wanted to create a simple email scraping(I’ve just started learning) chrome extension. However when i run it it doesnt return back any emails nor there shows any error can anyone help with what changes do i have to make. Here’s the link to my code (https://github.com/Mishannnnnn/web-scrap.git)

I don’t know if its the problem with the regex i did try a few.could someone please help me by reviewing my code.

adding tailwind classes for table borders dynamically doesn’t work

I have a bit of a custom table within my app , I receive data about which borders are there on each td tag

my border info property for example is TBLR , which means I have borders on top , bottom , left and right and so on
tailwind isn’t really picking up on individual borders for me ,
an example tag would look like this : Unit Supply temp in Econ mode but that doesn’t add the border colors ,

Here’s a sandbox with the example : https://codesandbox.io/s/tailwind-css-and-react-forked-dsy1em

Would love some help why these classes aren’t working

Div between text characters

I have a text element that is built when the user clicks a button. In the middle of that text, I added an input element.I want to make this process repeats seven times but it looks complicated. I actually made a lot of things but here are the important ones So, First I made an input element and a button when the user enter input and click the button what he wrote will be displayed in a h1 element with a random missing word Then,I made an input element in the that the missing word should’ve been in.What I want is that this to repeat this process seven times.

`function myFunction() {
    var x = document.getElementById("input").value;
    x=x+" ";
    var y=document.getElementById("inputed");
    var a,b='c';
    let c,d=[];
    var e;
    var f=0;
    const array =[];
    const z=x.length;
for(let index=-1;index<7;index++){
        a,b='c';
        c.push(0);
        d.push(0);
        c[index]=0;
        d[index]=0;
        e=1;
        f=0;
//Here the program will get a random space location and the space after it
    while(a!=' ' ){
        c[index]=Math.floor(Math.random()*x.length-2);
        a=x.charAt(c[index]);
    }
    d[index]=c[index];
    //The variable d will be the same as c and will increase until its value corrspends to a space
    while(b!=' ' ){
        d[index]++;
        b=x.charAt(d[index]);
    }
//I want the y.innerHTML to write from the 0 to c[0] then display the input element then from d[0] //to c[1] and display the input element again and form d[1] to c[2] until 7
    y.innerHTML = `${x.slice(
        0,
        c[0]
    )}<input type="text" style="color: gray;border:2px solid;border-radius: 10px;outline: none;
font-size: x-large;height:40px;width: 100px;" >${x.slice(
        d[0],
        z
    )} `;
}
}``

What does “Decoupling Implementation Details” mean regarding encapsulation in JavaScript?

I’m reading a blog post regarding encapsulation, after reading it I think I get what encapsulation is and why we need to use it, but at the end, the author talks about what are the advantages of encapsulation and he lists “Decoupling Implementation Details” as one of the benefits of using encapsulation.
I’m quoting it here:

Since Encapsulation enables operating on data using a public interface, it is easier to update the implementation because the tight coupling is eliminated. This is an excellent way to always code against an interface. This also means that with Encapsulation, the object is scalable to accommodate future changes without breaking compatibility.
The Coupling means the extent to which two modules are dependent on each other. Decoupling refers to eliminating such dependencies.

I’m trying to work this out in my head, and thought that maybe a SO member could help me understand what he is talking about. Can someone explain this to me?

Thanks in advance!

Conditional Rendering in react

I need to show and hide elements condtionally in react. I know we can condtionally render by creating boolean value for each element and and by manupulating particular boolean state variable we can conditionally show and hide elements. is there is any ways condtionally show and hide elements by not setting boolean variable for each elemnt in useState?

Here is the code. is there any ways to condtionally show and hide by not creating variable in state

  const [state, setState] = React.useState({
    ele0: true,
    ele1: true,
    ele2: true,
  });
  let arr = [1, 2, 3];

  const handleOnChange = (index) => {
    setState({ ...state, [`ele${index}`]: !state[`ele${index}`] });
  };
  return (
    <div className="App">
      {arr.map((ele, idx) => (
        <div key={idx}>
      {state[`ele${idx}`] &&    <h1>{`element${idx}`}</h1> }
          <button
            onClick={() => handleOnChange(idx)}
          >{`element ${idx} button`}</button>
        </div>
      ))}
    </div>
    )

How to used React-transliterate in div contentEditable custom Component

How can add React Transliterate in div contentEditable.. Please help me

  import './App.css';
    import EditText from "./component/EditText"
    import Tools from "./component/tools"
    import Header from "./component/header"
    import Img from "./component/img"
    import './scss/style.scss';
    import MyImage from './home.png';
    import React, { useState } from "react";
    import { ReactTransliterate, Language } from "react-transliterate";
    const  App = () => {
      const [text, setText] = useState("");
      const [message, setMessage] = useState('');
      const handleKeyDown = event => {
        console.log(event.key);

    if (event.key === 'Enter') {
      event.preventDefault();
 console.log(message);
console.log(event.target.value)
console.log('User pressed Enter ');

     
    }
  };
 
  // const [lang, setLang] = useState<Language>("hi");
  return (
    <div className="App">
      <Header/>
      <div className='App_leftbar'>
        <ul>
          <li>
            <a href='#'><img src={MyImage} /></a>
          </li>
        </ul>
      </div>
      <div className='App_centerbar'>
        
        <div
       contentEditable="true"
        id="message"
        name="message"
        value={text}
        onChange={event => setText(event.target.value)}
        onKeyDown={handleKeyDown}
      />
 <ReactTransliterate
        renderComponent={(props) => <EditText onChange={event => setText(event.target.value)}
        onKeyDown={handleKeyDown} {...props} />}
        value={text}
        onChangeText={(text) => {
          setText(text);
        }}
        lang="hi"
        placeholder="Start typing here..."
        id="react-transliterate-input"
      /> 
        <Img src={MyImage}/>
      </div>
      <div className='App_rightbar'>
        <Tools />
      </div>
    </div>
  );
}

export default App;

I used this npm https://www.npmjs.com/package/react-transliterate?activeTab=readme

import React, { useState } from "react";

import { ReactTransliterate } from "react-transliterate";
import "react-transliterate/dist/index.css";

const App = () => {
  const [text, setText] = useState("");

  return (
    <ReactTransliterate
      value={text}
      onChangeText={(text) => {
        setText(text);
      }}
      lang="hi"
    />
  );
};

export default App;

React Transliterate uses the event.keycode property to detect keys. Here are some predefined keys you can use. Or, you can enter the integer codes for any other key you’d like to use as the trigger

Style tag relative to overflow container width

How would i style an item in an overflowing div container according to the width of the container (NOT the content inside the container)

Visual explanation: (https://i.stack.imgur.com/WGA92.png)

I achieved the effect with javascript, but that would also be needed to run on edge cases (closing sidebar, …)

document.addEventListener('resize', (e) => {
    const width = document.getElementsByClassName('scrollContainer')[0].clientWidth - 20
    document.querySelector('item-child').style.width = width + 'px'
})

It that possible without any js?

How to change background color with tag and javascript? [duplicate]

I have a profile page for my webpage and would like for the background color to be changeable.

The method of changing is a <select> tag which then after pressing an update <button> onclick should call my function changeBackground()
This function gets the color chosen by the select tag Id and then changes the background

function changeBackground() {
  var colour = document.getElementById('background');
  if (colour == "dark") {
    document.documentElement.style.setProperty('--main-color', '#0F0F0F');
    document.documentElement.style.setProperty('--nav-color', '#303030');
  } else if (colour == "pink") {
    document.documentElement.style.setProperty('--main-color', '#FFAEC9');
    document.documentElement.style.setProperty('--nav-color', '#FF8AAD');
  } else {
    document.documentElement.style.setProperty('--main-color', '#00A2E8;');
    document.documentElement.style.setProperty('--nav-color', '#008BC7;');
  }
}
html {
  font-family: Bahnschrift;
  background-color: var(--main-color);
}

nav {
  background-color: var(--nav-color);
  padding: 15px;
  text-align: right;
}
<label for="background">Background:</label>
<select name="background" id="background">
  <option value="" selected="selected">Default</option>
  <option value="pink">Pink</option>
  <option value="dark">Dark</option>
</select>
<button type="button" onclick="changeBackground()">Update</button>

Each child in a list should have unique key prop and my browser router is also undefined

How to clear this problem.
Error in browser router
http://localhost:3000/Questions/undefined and

Each child in a list should have unique key prop.

`

const QuestionList = ({questionsList}) => {
 return (<div>
     {
      questionsList.map((question)=>(
        <Questions question={question} key={question.id}/>
      ))
     }
</div>
</>
 )
}

`

I am trying to build the new component page,i am expected that new component page is created,but as the result is Each child in a list should have unique key prop and my browser router is also undefined.

From NPM package create a standalone production ready JS file

Ive cloned this repo https://github.com/tpunt/lightweight-charts#boxes-install and i want to convert it to a standalone JS file (the OG tradingview repo provides it here: https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js

However the code I want to have is not in the OG repo its in a different one.

My question is: how do i get a standalone production . js file from this forked repo?