Converting this javascript code to React JS

I am integrating one tap sign in with phone on my website.
I am trying to convert following javascript code to React JS.

<div id="pheIncludedContent"></div>
<script src=""></script>
  var reqJson='{"success_url":"","client_id":"XXXXXXXXXXXXXXXXX","button_text":"Sign in with Phone","email_notification":"icon","button_position":"left"}';

My React JS code is:

import React, { useEffect } from 'react';

const SigninPhone = () => {
  useEffect(() => {
    // Create a script element
    const script = document.createElement('script');
    // Set the src attribute to the external script URL (Including from Phone Email)
    script.src = '';
    // Append the script element to the document body
    // Define the request JSON object
    const reqJson = {
      success_url: '',
      client_id: 'XXXXXXXXXXXXXXXXX',
      button_text: 'Sign in with Phone',
      email_notification: 'icon',
      button_position: 'left'
    // Call the log_in_with_phone function with the request JSON object

    // Clean up function to remove the script element when the component unmounts
    return () => {
  }, []); // Empty dependency array to ensure useEffect runs only once

  return <div id="pheIncludedContent"></div>;

export default SigninPhone;

But I am getting Uncaught TypeError: window.log_in_with_phone is not a function. Please help.

hello and welcome to fcc forum :slight_smile:

  • that supposedly should show that error!!
  • you can either run without using “window”, or if its need to be a “button” clicked function then run this as “click event” instead

happy coding :slight_smile:

Did you look at the docs?