React useContext() default value has not changed even I provide a value

Why is the UserContext default value has not changed even I specify a value in <UserContext.Provider>? How can I override the default value of the Context?

this is the App.jsx

import './App.css';
import React, { createContext } from 'react';
import ComponentB from './components/hooks/context/ComponentC';

function App() {
  return (
    <div className="App">
      <ComponentB />
    </div>
  );
}

export default App;

this is the ComponentB

import React, { createContext, useState } from 'react';
import ComponentC from './ComponentC';

export const UserContext = React.createContext('default');
export const ChannelContext = React.createContext('default');

const provider = UserContext.Provider;

function ComponentB() {
  return (
    <div>
      <provider value='Username'>
        <ComponentC />
      </provider>
    </div>
  );
}

export default ComponentB;

this is the ComponentC

import React from 'react';
import ComponentE from './ComponentE';

const ComponentC = () => {
  return <ComponentE />;
}

export default ComponentC;

this is the ComponentE

import React, { Component, useContext } from 'react';
import { UserContext, ChannelContext } from './ComponentB';

const ComponentE = () => {
  const username = useContext(UserContext);
  const channel = useContext(ChannelContext);

  return <div>username : {username} channel : {channel}</div>;
}

export default ComponentE;

React: How do I use values from an object’s specific key?

I am new to React and am trying to figure out how to return a particular objects entry by it’s key.

So far, I have an object as such:

const questions = [
  {
    id: '1',
    section: 's1',
    answers: [
      "answer a",
      "answer b",
      "answer c",
      "answer d",
    ]
  },
  {
    id: '2',
    title: 'Question 2',
    answers: [
      "answer a",
      "answer b",
      "answer c",
      "answer d",
    ]
  },
  //etc

which I am currently iterating through and using parts of as props in a component, eg:

  return (
    <div>
      {questions.map((question) => (
        <Question
          key={question.id}
          questionNum={question.id}
          title={question.title}
          answers={question.answers}
        />
      ))}
    </div>
  );

This works fine and as expected.

But now I need to modify this so it only returns the values of 1 given particular key in the object.

I’ve been searching and experimenting with .get() but to be honest I’m really stumped with how to do this.

Would anyone know the best way to approach this?

How to stream the streamed data from Websocket to another Websocket?

This is the image to help you understand what are the problems. I am trying to stream my data being streamed by Websocket to another Websocket.

ws.on('message', function (msg){
let off = msg.data.search(/st5/)
if (off !== -1) {
    //console.log(`${msg.data.slice(83,85)}`)
    if (msg.data.slice(83) === ',') {
        console.log(`${msg.data.slice(84,89)}`)



    }
    else {
            console.log(`${msg.data.slice(83,88)}`)
            var k = msg.data.slice(83,88)

            wss.on('connection', wss => {
                wss.send(`${k}`)

            })


    }
}
else{
    if (msg.data.search('~m~~h~') !== -1) {
        ws.send(`${msg.data}`)
        console.log(`TX: ${msg.data}`)
    }
  }
})

When the client connects to the websocket all the data I have received are automatically sent at the exactly same time. I want to keep sending my data not at the connection time with the load of data. Is there anything I have to do with wss.on(‘connection’)?

How to reload page on language change in google translate for html / Reactjs?

Coding Used for Google Script in Our Program

<script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" async> </script>

<script type="text/javascript">

  function googleTranslateElementInit() {
    new google.translate.TranslateElement(
      {
        pageLanguage: "en",
        
         includedLanguages : 'ta,te,hi,ml,kn,en',

        layout: window.google.translate.TranslateElement.InlineLayout.SIMPLE,

        

      }, 
      'google_translate_element'  
    );
  } 
 
</script>
 

———- Using Below Code —– To Display the Dropdown value or HTML / Reactjs ——

<div id="google_translate_element">

function not written right

I need to fine tune this function if the conditions in the where clause are true. I’m new at functions so this should be easy for those of you who know them well…Ultimately, if the statement is true, I need it to execute a call to yet another function.

function get_log_contentaging( $user_id, $ref , $ref_id = null ) {

global $wpdb, $logsource;
$request = "SELECT creds FROM {$logsource->log_table} WHERE user_id = '$user_id' AND ref= 'published_content' AND time > strtotime('-2 day', time())";

if ( ! empty( $ref_id ) ) {
    $request .= " AND ref_id = '$ref_id'";
}

return $wpdb->get_var( $request );}/* if the select statement for the user ID is true, then execute this- new Controller({'minDelay':3000, 'minCount':2, 'maxCount':25, 'mouseOver':'fly'});*/

EJS template engine

I’m doing a node.js project and I’ve an ejs template file which further uses templates for header and footer.

template.ejs looks like this:

<%- include(header) %>
main html body
<%- include(footer) %>

<script type='text/javascript'>
...
...
...
</script>

when I run the server, the script embedded between the script tags becomes clearly visible. How do I hide this part from the page rendered by the node server.

Using a constant random variable in a randomly generated component

I am building a solar system app that automatically generates stars. My stars are a React component that accept a couple of props. When the user clicks the star, I need the system state to update and also I want the navlink to point to the same value.

let randomTypeVariable = starList[Math.floor(Math.random() * 6 + 1)];
      return (
        <NavLink
          to={`/${randomTypeVariable}`}
          onClick={() => props.setSystem(`${randomTypeVariable}`)}
          className="starWrapper"
        >

However at the moment the to= prop and the onClick function are giving different results. I know that this is because the randomTypeVariable is running each time and giving different results.

These components are being randomly generated so I cannot have the variable be a constant value.
How can I assign both of these properties to be the same randomly generated variable?

For context here is the full star component

let randomTypeVariable = starList[Math.floor(Math.random() * 6 + 1)];
  const makeStars = (Count = 5) => {
    if (Count > 0) {
      return (
        <NavLink
          to={`/${randomTypeVariable}`}
          onClick={() => props.setSystem(`${randomTypeVariable}`)}
          className="starWrapper"
        >
          <Star
            starName={`${makeStarName()}`}
            starPosition={positionList[Math.floor(Math.random() * 9 + 1)]}
            starType={`${starList[Math.floor(Math.random() * 6 + 2)]}`}
          ></Star>
          {makeStars(Count - 1)}
        </NavLink>
      );
    }
  };

How to extract token from Authorization header response using Fetch API?

I have a react app that makes a post request using the Fetch API and receives a Response that has a token in the Authorization header. I want to store that on the client-side in the cookies. And when I make a different request I will get that token from the cookies and send it through the header. How do I go about extracting this token from the header and storing it in cookies?

Get Api value and put in a const – VUE

i’m inserting recaptcha invisible at one system, but i need to get the secrets from database.

I have one method getting the value, but i need to save it in a const and pass to recaptcha method.
what i did, is not working.

how is working:

RecaptchaSiteKeyApi.js – Getting the key from backend api – here is working.

import { api } from './ApiConfig'

export default {

listaSiteKey: () =>
        api.get(`recaptcha-site-key`,
            {
            headers: { Authentication: window.localStorage.getItem('token'), "Content-Type": "application/json" },
            transformResponse: [function (data) {
                const result = data ? JSON.parse(data) : null;
                return result.nmSite;
            }]
        }),

    }

RecaptchaSiteKey.js – to save the result from Api in a const and send to LoginPage –here is not working the value from listasitekey() not apear.

import RecaptchaSiteKeyApi from './RecaptchaSiteKeyApi';

const CHAVE_RECAPTCHA = {
    key: null
}

export function carregarChaveCaptcha() {
    if(CHAVE_RECAPTCHA.key==null){
        CHAVE_RECAPTCHA.key = RecaptchaSiteKeyApi.listaSiteKey();
    }    
    return CHAVE_RECAPTCHA.key;
}

Login.vue – here is the recaptcha method
i need to pass the value to these component:

          <RecaptchaEnterprise 
            :data-sitekey="constKey()"  <------- need to put the value key here
            :data-validate="validate"
            :data-callback="callback"  
              data-badge=""           
             >Acessar
            </RecaptchaEnterprise>
            </v-btn> 

export default {
  components: {   
    RecaptchaEnterprise 
  },
  data() {
    return {
      key: null,

            
    };
  },

  methods: {

    constKey(){
      const Key = carregarChaveCaptcha();
      return Key
    },

Debug:
RecaptchaSiteKey – not get the value from SiteKeyApi
RecaptchaSiteKeyApi – is getting the value from database

i have vue app and it says This dependency was not found: * core-js/fn/object/create in ./src/main.js

here is my dependencies
“dependencies”: {
“axios”: “^0.25.0”,
“bootstrap”: “^5.1.3”,
“bootstrap-vue”: “^2.21.2”,
“core-js”: “^3.20.3”,
“vue”: “^2.6.11”,
“vue-router”: “^4.0.12”
},
“devDependencies”: {
“@vue/cli-plugin-babel”: “~4.5.0”,
“@vue/cli-plugin-eslint”: “~4.5.0”,
“@vue/cli-service”: “~4.5.0”,
“babel-eslint”: “^10.1.0”,
“eslint”: “^6.7.2”,
“eslint-plugin-vue”: “^6.2.2”,
“node-sass”: “^7.0.1”,
“sass-loader”: “^12.4.0”,
“vue-template-compiler”: “^2.6.11”
},

javascript – unable to get response from promise.all()

I find that I cannot get the response when using promise.all.

The orders below should be an array

Promise.all(promises).then(function (orders) {
  console.log(orders); // nothing logged
});

Full code

let promises = markets.map(async (mkt) => {
  return new Promise(async function (resolve, reject) {
    return functionA(paramA)
      .then(resA => {
        return res.functionB()
          .then((resB) => {
            if (resB.length > 0) {
              return functionC()
                .then(resC => {
                  console.log(resC); // successfully logged
                  return resC;
                });
            }
          });
      })
      .catch(err => console.log(err));
  });
});
Promise.all(promises).then(function (orders) {
  console.log(orders); // nothing logged
});

How can I fix?

Run This Script On Every Tab Except “Main” Tab

I have this script working well, but I’m uncertain how to make it run on every tab not labeled “Main”. Thanks in advance!

function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Dude");       // Enter sheet name

var row = s.getRange('A2:A').getValues();  // Enter column letter that has the text "hide" and  "unhide"
var cell = s.getRange('A1').getValue();

s.showRows(1, s.getMaxRows());
for(var i=0; i < row.length; i++){ if(row[i] != cell) { s.hideRows(i+2, 1); }   // Value to hide
     
}
}

Jerome