Action only happens after second button press

I have a button called signOut which changes a context value and signs a user out of my web app, however it seems to be only performing these changes after I click the button for a second time.

Initially, I thought it was because the process was async and so the header component was being rendered before the context has changed, however (and I know its dodgy) to check this I added a setTimeout and only navigated to the home page after 2 seconds which still didn’t fix it.

    const signOut = () => {
        setUserDetails({"displayName":""})
        auth.signOut().then(() => {
            console.log(userDetails)
            navigate("/")
        })
    }

Here is the code I call onClick

Here is the code for the header (which should rerender after userDetails is updated)

    useEffect(() => {
        console.log(userDetails.displayName)
        if (userDetails.displayName !== "") {
            setLoginUser(userDetails.displayName)
            setLoginUserPath("/settings")
        } else {
            setLoginUser("Log in")
            setLoginUserPath("/login")            
        }
    }, [userDetails.displayName])

here is the context:

  const userDetails = createContext({
    userDetails: {"displayName":""},
    setUserDetails: (input) => {}
  });

This is what happens when I click the sign out button the first time
enter image description here

This is what happens the second time I click the same button (note header.js now returns an empty string rather than “Toby”)
enter image description here

Apologies if this is a duplicate question, I haven’t been able to find anything too similar (although I feel as though its going to have a really simple answer that Ive massively overlooked).

How to create a text component where first word of sentence to be bold?

I’m trying to create a text component where first word of the sentence to be bold. Right now with my solution, when a user enter “Tips: favourite vacation”, I get ” Tips: favouritevacation”, where rest of sentence becomes mess and no space is created after Tips:. This isn’t elegant solution. I thought about creating another component like TextBold and use it like this < Text >< TextBold >Tips:< /TextBold > Your Vacation< /Text >, but this seems unnecessary. Is there a way to get this working within Text component alone? https://codesandbox.io/s/text-component-v2dbt?file=/src/App.tsx

import * as React from "react";

export interface TextProps {
  children?: string;
}

export const Text: React.FunctionComponent<TextProps> = ({
  children
}: TextProps) => {
  return (
    <>
      <span style={{ fontWeight: "bold" }}>{children?.split(" ")[0]}</span>
      <span>{children?.split(" ").slice(1)}</span>
    </>
  );
};

export default function App() {
  return (
    <div>
      <Text>Tips: favourite vacation</Text>
    </div>
  );
}

Change default dash(“-”)to blank in bootstrap table

I have a web app, frontend has a bootstrap table, backend using Restful API to render the data.

In the bootstrap table, the null value displays dash by default.

I want to change the default dash to blank for all the data.

I have tried this method:Bootstrap table, dashes / hyphens in empty cells,

    $('#bk-table').bootstrapTable({
        undefinedText: ''
    });

But it did not worked for me, the table still displays dash as default for null value, and in the console no error shows.

How could I change default dash(“-”)to blank in bootstrap table?

How do I control timing of javascript execution in relation to other scripts loading dynamic content?

I’ve created a small piece of javascript to target some dynamically loaded HTML from a plugin script (YOTPO Reviews).

<script type="text/javascript">
if(window.location.hash) {
    document.getElementsByClassName('write-review-wrapper')[0].style.display = "block";
}
</script>

I’m running into ‘x is not defined’ type errors and I assume this is because my script is running before the Yotpo widget script has finished loading the HTML I’m selecting?

I know I can execute the script after the DOM has loaded with the window.onload state and this works, however because I’ve got so many other scripts that are taking time to load in, such as live chat, tracking etc. It’s too slow and what I’m trying to achieve becomes somewhat pointless.

The YOTPO script loads in an acceptable time, but how can I get my script to execute just after it’s loaded (if that is indeed the issue here)?

How to make image clickable and redirect to its introduction value page in Reactjs

I have called an api then pick let says drinks. i picked drink name and images. Now i need to find the details about that drink.On clicking in this image it show about that . which all these think are present in the api. But i dont know how to do it.

import React from "react";


const DrinkList = (props) => {

  // const handleTextShow
  return (
    <>
      {props.drinks.map((drink, index) => (
        <div>
          <img
            src={drink.strDrinkThumb}
            alt="drink"
            width="300"
            height="300"
            onClick={handleTextShow}
          ></img>
        </div>
      ))}
    </>
  );
};

export default DrinkList;

strDrinkThumb shows photo about that and details be strDetails.

why CSS is not in my second div in cordova

i have this 2 div in my body, the first one shows tables, the second one has a form with input select and buttom, and it must shows itself when i click a table from the first one, this tables call a function that hide the first div with id=”pagina1″ and the show the div with id=”pagina2″, using the command $(“#pagina1”).hide() and $(“#pagina2”).show(), the problem is that for some reason css is not working the both div, it only works in the first div that it is declared

<div data-role="page" id="pagina1">
        <div data-role="header" data-position="fixed">
            <h1>LISTADO DE REMITOS PENDIENTES </h1>
        </div>

        <div data-role="content">
            <div id="idResultado"></div>
        </div>

        
    </div>

    <div data-role="page" id="pagina2">
        <div data-role="header" data-position="fixed">
            <h1>Registro de Remito </h1>
        </div>

        <div data-role="content">
            <div class="titlepage">Ingrese los datos </div>
            <div class="ui-field-contain">

                <input type="text" id="txtCodRemito" data-clear-btn="true" placeholder="Codigo Remito" required />
                <input type="datetime-local" id="txtfecha" name="birthdaytime">
                <select id="cbProveedor">
                    <option value="-1">Seleccione un Proveedor</option>
                </select>

                <select id="cbCombustible">
                    <option value="A">Seleccione un Combustible</option>
                    <option value="B">Debe Seleccionar un proveedor para cargar los combustibles</option>
                </select>

                <input type="text" id="txtLitros" data-clear-btn="true" placeholder="Litros Cargados" required />
                <input type="text" id="txtMonto" data-clear-btn="true" placeholder="Monto Total" required />
                <button id="btnCamara">Foto de Remito</button>
                <div style="border: 1px solid; width: 200px; min-height:100px; margin: 0 auto;">
                    <img src="" id="myImage" />
                </div>
                <button id="btnRegistrar">Registrar</button>
            </div>
            <div id="idResultado"></div>
        </div>
    </div>

RxJs: concat two observables as options for material select

I am having problems trying to concat two different observables and show the results into a Material Select component.

On this example (built using the tool from Material docs) there is a simple example simulating what I want to do. Options are not being shown.

In my current code (on my machine), the problem I see is: the first Observable that is passed to the concat operator is subscribed and all items are shown in the Select. But I belive that the first Observable never completes. It looks like material-select is not “completing” the first Observable and, because of that, concat won’t subscribe to the next Observable while the first one never completes, as it says in its docs:

Note that if some input Observable never completes, concat will also never complete and Observables following the one that did not complete will never be subscribed.

What I need is this: taking two different Observables (with different data in each one), concat them (or any other operation), and, in the end, show all their data combined as options of a single select component.

Just as a reference, I’ll copy the code here also, so it won’t be lost in the future:

// Component:
import { Component, Input } from '@angular/core';
import { from } from 'rxjs';
import { concatWith } from 'rxjs/operators';

interface Option {
  value: number;
  label: string;
}

@Component({
  selector: 'select-overview-example',
  templateUrl: 'select-overview-example.html',
})
export class SelectOverviewExample {
  @Input()
  options$: any;

  constructor() {}
  ngOnInit() {
    // Let's pretend this data comes from API 1
    const sourceA$ = from([
      { value: 1, label: 'Value 1' },
      { value: 2, label: 'Value 2' },
      { value: 3, label: 'Value 3' },
    ]);

    // And these ones comes from API 2
    const sourceB$ = from([
      { value: 4, label: 'Value 4' },
      { value: 5, label: 'Value 5' },
      { value: 6, label: 'Value 6' },
    ]);

    // Now, concat the data from both observables and display all of them as options in a Select component:
    this.options$ = concatWith(sourceA$, sourceB$);
  }
}

And the template:

<h4>Basic mat-select</h4>
<mat-form-field appearance="fill">
  <mat-label>Select some value:</mat-label>
  <mat-select>
    <mat-option
      *ngFor="let option of (options$ | async)"
      [value]="option.value"
    >
      {{option.label}}
    </mat-option>
  </mat-select>
</mat-form-field>

Video size resets momentarily when changing src

When I change the src of a video, it momentarily shrinks to its default size and scrolls the screen up, but once it loads, the screen doesn’t go back down. How can I prevent the resetting of the video, and make it so it does not scroll up? Here’s the code:

      <div class="leftArrow">
        <a aria-label="Previous Video" class="lArrow" onclick=lastVideo()><img src="source/leftArrow.png" class="arrow"></a>
      </div>
      <div class="video" >
        <video src="video.mp4" id="video" controls autoplay>Video not supported</video>
      </div>
      <div class="rightArrow">
        <a aria-label="Next Video" class="rArrow" onclick=nextVideo()><img src="source/rightArrow.png" class="arrow"></a>
      </div>
    </div>
    var title = document.getElementById("title");
    title.innerHTML = titleList[currentVideo];

    var desc = document.getElementById("desc");
    desc.innerHTML = descList[currentVideo];

    var video = document.getElementById("video");
    video.src = aList[currentVideo]; 
    
    video.load();
    video.play();
    return;
}

function nextVideo() {
    if (currentVideo == aList.length - 1) {
        currentVideo = -1;
    }
    currentVideo++;
    loadVideo();
}

function lastVideo() {
    if (currentVideo == 0) {
        currentVideo = aList.length;
    }
    currentVideo--;
    loadVideo();
}

How can I add Signature Pad to my Rails App?

I’m trying to figure out how to add a signature pad field (from: https://github.com/szimek/signature_pad) in my Rails app but I have no idea how to implement it for MVC file structure in a Rails app. I don’t even want to use a rails form, just html for this particular use case but I just CANNOT get the JS to work and it’s incredibly frustrating.

I don’t understand the documentation after the installation process via yarn. If anyone can help, I’d really appreciate it.

Regex string split with multiple conditions

(Javascript older version of Node.js)

I have multiple lines like these

var name1;

CONST name2

Let name3;

My desired outputs are

name1

name2

name3

So I am trying codes like this.

/[^;]*/

But I need help because I have multiple patterns. Some may have semicolons/space/null after the variable names, I need to omit those.

React Native: How can I render the results from an expo-sqlite successCallback in my view?

I’m using expo-sqlite to call a local database in react native. https://docs.expo.dev/versions/latest/sdk/sqlite/

I’ve tried to consume the JSON and have tried to use promises but each time I’m met with undefined when I attempt to render the data in my view. Below is my simplified layout.

How can I render this data from the sqlite successCallback?

repository.js

export const readTodos = () => {
  db.transaction((tx) => {
    tx.executeSql(
      "SELECT * FROM todos",
      null,
      (_, { rows }) => JSON.stringify(rows),
      (error) => console.log(ERROR_MESSAGE, error)
    );
  });
};

rows data

Array [
  Object {
    "id": 1,
    "name": "homework",
  },
  Object {
    "id": 2,
    "name": "walk dog",
  },
]

TodosScreen.js

import * as React from "react";
import { Text, StyleSheet } from "react-native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { readTodos } from "../storage/repository";

const Stack = createNativeStackNavigator();

function TodosScreen() {
  var todoJSONdata = readTodos(); //

  return <Text>I WANT TO RENDER ROW DATA HERE</Text>;
}

export default TodosScreen;

Destructuring values from an object and assigning it to another object in one go? [duplicate]

I am having 100s of data in request.body and I want only 20 of them but those 20s are getting used in other places too. Can I assign it to another object in the same line after destructuring it?

Example:

const { firstName, lastName, age, role, gender, place } = req.body;  

Can I assign the above destructured data to another object while destructuring it?
I want the equivalent result of below code but in the same line and that too while destructuring it.

const userDetails = { req.body.firstName, req.body.lastName, req.body.age, req.body.role, req.body.gender, req.body.place }