Re-render single element of an React component

I am working on a TO-DO List React App. The goal is, that every time the user clicks on the “Add” button the saveNote() function gets called and a new note is added to the notesobject. Then the page should automatically re-render and by that the addNote() function gets called and returns all notes within notes object as a new <li> item.

Right now adNote()only gets called after I clicked on the Addbutton and start entering a new note .. why?

import React from "react";
// import Note from "./Note";
const notes = [
  {
    id: 1,
    content: "Test"
  }
];

let counter = 1;

function App() {
  const [note, setNote] = React.useState("");

  function createNote(event) {
    setNote(event.target.value);
  }

  function saveNote() {
    counter++;
    notes.push({ id: counter, content: note });
    console.log(notes);
  }

  function addNote(note) {
    return (
      <li key={note.id}>
        <span>{note.content}</span>
      </li>
    );
  }

  return (
    <div className="container">
      <div className="heading">
        <h1>To-Do List</h1>
      </div>
      <div className="form">
        <input onChange={createNote} value={note} type="text" />
        <button onClick={saveNote} type="submit">
          <span>Add</span>
        </button>
      </div>
      <div>
        <ul>
          <li>A Item</li>
          {notes.map(addNote)}
        </ul>
      </div>
    </div>
  );
}

export default App;

Heremaps Infobubble CSS does not change

so I looked up every possible solution for changing the CSS style of the infoBubble for heremaps. I work with Angular v8 and thus far only setting the css of the Data has worked for me, but that does not influence the color of the marker.

const marker = new H.map.Marker(position);
marker.setData("<div style='width: 100px'>Hello world!</div>");

marker.addEventListener("tap", event => {const b = new H.ui.InfoBubble(event.target.getPosition(), {content: event.target. getData()}); this.ui.addBubble(b);}, false);

this.map.addObject(marker);

This css code did not work for me:

background-color: yellow;
height: 275px;
}

Anyone know as to why it is not working?

How can I possible shorten this JS code to be more readable?

I have the following code:

    ctrl = {
        dataHolder: {
            hide: _ => {
                this.dataHolderTarget.style.display = 'none'
            },
            show: _ => {
                this.dataHolderTarget.style.display = 'block'
            }
        },
        dataBtnHolder: {
            hide: _ => {
                this.dataBtnHolderTarget.style.display = 'none'
            },
            show: _ => {
                this.dataBtnHolderTarget.style.display = 'block'
            }
        },
        playerOneBtn: {
            hide: _ => {
                this.playerOneBtnTarget.style.display = 'none'
            },
            show: _ => {
                this.playerOneBtnTarget.style.display = 'block'
            },
            load: res=>{
                this.dataset.res=res
            }
        },
        playerTwoBtn: {
            hide: _ => {
                this.playerTwoBtnTarget.style.display = 'none'
            },
            show: _ => {
                this.playerTwoBtnTarget.style.display = 'block'
            },
            load: res=>{
                this.dataset.res=res
            }
        }
    }

How can I make so I don’t repeat those code blocks? As I’m aware of DRY, this code looks somehow ugly. As you can see hide and show are everywhere. The last 2 elements have load functions.

Command PhaseScriptExecution failed with a nonzero exit code XCODE react-native project

/Library/Ruby/Site/2.6.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
    from /Library/Ruby/Site/2.6.0/rubygems.rb:284:in `activate_bin_path'
    from /usr/local/bin/bundle:25:in `<main>'
    from /usr/local/bin/ruby_executable_hooks:22:in `eval'
    from /usr/local/bin/ruby_executable_hooks:22:in `<main>'
Command PhaseScriptExecution failed with a nonzero exit code

After this error ios build failed.

I expect to successfully build my ios app

How to call variable in jquery to put inside {{ Storage::url() }}

i have datatables in laravel 8 and i was encode a table to get some atribute, the code like this
Controller

i want to call r.file to get value for access the path of file,
the path file like this = “assets/file/Dr3cxy0QM2GDH1IpaWeiMZDUXfTVhl6QkazEyKYh.pdf”

Blade View

but the result like this
Browser

how to make the href value like this?

<a href="/storage/assets/file/Dr3cxy0QM2GDH1IpaWeiMZDUXfTVhl6QkazEyKYh.pdf">Test.pdf</a>

How do I resend the OTP using fireabse and react

I was trying to implement resend otp functionality to a resend button in my react app.
Here is the function,

const handleResend = () => {
const number = "+91" + mobile;
const appVerifier = window.recaptchaVerifier;
signInWithPhoneNumber(number, appVerifier);
};

Tried a solution from, Not able to resend OTP using firebase auth in ReactJS this question. But didn’t solve the problem. Any suggestion will be appreciated.

Share programming logic between Android an Web

I have an Android app and I’m making a web version currently.

In the app there are many utility files, let’s say, for the sake of an example, a class that just formates a string in a certain way.

Is there any way to program this just once for both platforms (android and web), and not have separate implementations for Android in Java/Kotlin, and one for Web in JS/TS?

Calculated value from JS function cannot be read in ASP.Net

I calculate value from two text boxes and successfully insert to result textbox using JS function. As I checked, the typeof(num3.value) is string. Refer JS function below.

   <script type="text/javascript">
    var num1 = document.getElementById('<%= txtDuration.ClientID %>');
    var num2 = document.getElementById('<%= txtHeadcount.ClientID %>');
    var num3 = document.getElementById('<%= txtTotalHours.ClientID %>');
    num1.onchange = multiplyNumbers;
    num2.onchange = multiplyNumbers;

    function multiplyNumbers() {
        num3.value = parseFloat(num1.value) * parseFloat(num2.value);
    }
   </script>

But once I want to store it the value using my stored procedure, it does not read any value and return [FormatException: Input string was not in a correct format.] error.

My store procedure

Using con As New SqlConnection(SqlConnection)
        Using cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "Training_InsertTraining"
            cmd.Parameters.Add("@THours", SqlDbType.Float).Value = txtTotalHours.Text
            cmd.Connection = con
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
            con.Dispose()
         End Using
    End Using

Please someone know whats the problem. txtTotalHours.Text return Nothing

How to filter out data on the basis of empId then projId in array of object?

I have an array of objects which is having individual task and I need to filter out the each task according to employee id and then project id and after this I need to check if the sum of hours in the resulting array is less than 4.
If all these conditions satisfy then store those values in the array.
This is the response from api.

nonallocated: [
  {
    empId: "1",
    task: {
      project: {
        projectId: "111"
      },
      total: '2'
    }
  },
  {
    empId: "2",
    task: {
      project: {
        projectId: "111"
      },
      total: '3'
    }
  },
  {
    empId: "1",
    task: {
      project: {
        projectId: "222"
      },
      total: '1'
    }
  },
  {
    empId: "1",
    task: {
      project: {
        projectId: "111"
      },
      total: '1'
    }
  }
]

How to show the data from the api to the nested field in reactjs

`

import axios from 'axios'
import { CART_ADD_ITEM } from '../constants/cartConstants'


export const addToCart = (uid, qty) => async (dispatch, getState) => {
    const { data } = await axios.get(`/api/v1/`)

    dispatch({
        type: CART_ADD_ITEM,
        payload: {
            product: data.uid,
            name: data.name,
            images: {[
                url: data.url,
            ]} 
            price: data.price,
            countInStock: data.countInStock,
            qty
        }
    })

    localStorage.setItem('cartItems', JSON.stringify(getState().cart.cartItems))

`

`

`

import axios from ‘axios’
import { CART_ADD_ITEM } from ‘../constants/cartConstants’

export const addToCart = (uid, qty) => async (dispatch, getState) => {
const { data } = await axios.get(/api/v1/)

dispatch({
    type: CART_ADD_ITEM,
    payload: {
        product: data.uid,
        name: data.name,
        **images: {[
            url: data.url, this part is where the challenge
        ]}** 
        price: data.price,
        countInStock: data.countInStock,
        qty
    }
})

localStorage.setItem('cartItems', JSON.stringify(getState().cart.cartItems))
`
this what i came up with but it seems i have made a mistake on the nested image value but everything works just fine...can someone help with that bit there

Split String by backslash in JavaScript (JS)

var stringName = “Hello 12 check”;

Hi i have string
and i want to split by the backslash. Please, can anyone suggest how i can handle this
I have tried with backslash, regex, replace, split method and unicode of backslash but none of method is use for me

Catch exception in dynamically added scripts in ReactJs

I have a function that adds an external script dynamically. here is my code

try {
   const script = document.createElement('script');
   script.src = 'script url';
   script.async = isAsync;
   document.body.appendChild(script);
 } catch(e){
   console.log(e);
 }

but when exception occurs in the script, try catch not catching that error. Also my code is inside react error boundary but still my react app crashes on script error.

How to add a keyword before string using regex in JS?

I am making an application where I have a string from which I will form an array with the help of regex.

Eg..,

String: DEVICE_SIZE IN ('036','048', '060','070')

Output:

{
    "DEVICE_SIZE": [
      "036",
      "048",
      "060",
      "070"
    ]
}

Like this for all string, we follow the following code to get the array data.

Here if there is a NOT keyword before the key, then we add NOT *key* like "NOT DEVICE_DISCHARGE_AIR"

Requirement:

I have a string like NOT (DEVICE_SERIES IN ('LV') AND DEVICE_VOLTAGE IN ('A','8') AND DEVICE_SIZE IN ('007','009','012','018')).

So here after NOT there is a parenthesis, so after NOT if there is a parenthesis then I need to add the key as

"NOT DEVICE_SERIES":["LV"],

"NOT DEVICE_VOLTAGE":["A", "8"] ,

"NOT DEVICE_SIZE": ['007','009','012','018']

Current scenario:

But right now, it is not adding the NOT keyword before of key.

Working Example:

const stringOne = "DEVICE_SIZE IN ('036','048', '060','070') AND DEVICE_VOLTAGE IN ('1','3') AND NOT DEVICE_DISCHARGE_AIR IN ('S') AND NOT DEVICE_REFRIGERANT_CIRCUIT IN ('H', 'C')";

const stringTwo = "DEVICE_SERIES IN ('LV') AND DEVICE_ELECTRICAL IN ('K') AND NOT (DEVICE_SERIES IN ('LV') AND DEVICE_VOLTAGE IN ('A','8') AND DEVICE_SIZE IN ('007','009','012','018'))";


const regex = /((?:bNOTs+)?w+)s+INs+('([^()]*)')/g;

const getTransformedData = (string) => {
   return Array.from(
  string.matchAll(regex), m =>
  ({
    [m[1]]: m[2].split(/',s*'/)
  })
 )
}


console.log(getTransformedData(stringOne)); // Working fine

console.log(getTransformedData(stringTwo)); // Need to include NOT infront of each key as it is union

How can I add NOT keyword in front of each key if it comes with the pattern of NOT and then the parenthesis?

Expected result:

"NOT DEVICE_SERIES":["LV"],

"NOT DEVICE_VOLTAGE":["A", "8"] ,

"NOT DEVICE_SIZE": ['007','009','012','018']

How to send blob as binary without using FormData

Every guide shows that you need to append the blob to a FormData object and post that FormData to upload a binary. Isn’t there a way to convert to binary without this.

form = new FormData()
form.append("file", someBlob)

When FormData is used, the field is shown as “binary” in the network tab. I tried readAsArrayBuffer, but it just shows {}. So, I don’t know if it works.

With Form Data

With readAsArrayBuffer

I think the backend doesn’t accept FormData, that’s why I don’t want to use it.