how to open hamburger menu in ReactJs?

how to open hamburger menu in ReactJs? – Stack Overflow

node.js – Role based authentication using Firebase and ReactJS

This is a advice seeking type post

I want to have two user types:

User
Admin
I’m going to user Firebase for authentication part only. Now let’s see what my users can do:

Register/login
Create post and make it public/private
Make a collection of post and make it public/private
And here’s what my admin can do:

Login
CRUD operation on users
View public/private posts and delete them
View public/private collection of posts and delete them
My question is can I do all of this using just Firebase and ReactJS? Or do I need a custom backend?

And what my rules for authenticaion for admin and user should look like if I just want a RBAC?

Is this enough?(found it in an article):

{
  "rules": {
    "users": {
      "$user": {
        ".write": "auth !== null && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)",
        ".read": "auth !== null && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)"
      },
      ".write": "auth !== null && auth.token.isAdmin === true",
      ".read": "auth !== null && auth.token.isAdmin === true"
    }
  }
}

reactjs – React Native Text Input place the text on bottom of the input

I have a text input in react native and by default, the text is centered in the input box

Is there a way to have the text on the bottom of the input, as if there is 0 padding between the bottom border of the input box and the text?

<TextInput
   type='submit'
   style={styles.input}
   onChangeText={text => this.setState({ name: text })}
   title='Name'
   value={this.state.name}
/>
input: {
        height: 40,
        width: 250,
        margin: 12,
        borderRadius: 0,
        backgroundColor: 'white',
        borderBottomWidth: 1 
}

reactjs – ¿Cómo hacer que el estado de un componente hijo repercuta en el del padre?

Estoy intentando hacer un menú hamburguesa con react. Para esto utilizo una librería externa que al agregar la clase “is-active” al botón del menú este realiza la animación correspondiente, para que en vez de ser la opción de “abrir el menú” sea la opción de “cerrar el menú”.

Los dos componentes son estos:

Componente padre:

import MenuHamburguesa from './MenuHamburguesa';
import Menu from './Menu';

export default function Header(props){
    return(
        <header className="header">
            Merluzadepincho
            <MenuHamburguesa/>
            <Menu/>
        </header>
    );
}

Y componente hijo (el botón del menú):

import '../hamburgers-master/dist/hamburgers.css';
import React, { useState } from 'react';

export default function MenuHamburguesa(props){
    const (className, setclassName) = useState("hamburger hamburger--minus");
    
    let isActive = () =>{
        className.includes("is-active") ?
        setclassName("hamburger hamburger--minus") :
        setclassName("hamburger hamburger--minus is-active");
    }

    return(
        <button className={className} type="button" onClick={isActive}>
            <span className="hamburger-box">
                <span className="hamburger-inner"></span>
            </span>
        </button>  
    );
}

Sin embargo necesito que al cambiar el estado del componente hijo (MenuHamburguesa), el componente <Menu> (que hasta el momento era invisible), se vuelva visible. ¿Cómo puedo hacerlo siendo que <Menu> está en un nivel superior que <MenuHamburguesa>, pero es <MenuHamburguesa> el que posee en onClick?

react.js – not able to give proper css to my bootstrap element in react

when creating a navigation bar in my react based website , the react code :
 this is the code

 `<ul className="navbar-nav ml-auto mb-2 mb-lg-0">`

 

now, on the ul tag (line 28) () i want to give margin right auto (mr-auto) instead of (ml-auto) which is margin-left :auto but it is not working and i had already import all necessary bootstrap import in my index.js file in react . and i copied this code from bootstrap itself under components > navbar

javascript – Implement function to delete item reactjs

I have the following task app, I am trying to implement a function to delete tasks. The app is divided into several functional components. The app is divided in several components as a practice and for a simpler implementation later with firebase.

Component 1

export default function App() {
  const (task, setTask) = useState(());

  function handleCallback(value) {
    setTask((...task, value)); // I save the getter value to a new pointer in memory
  }

  return (
    <div className="app">
      <div className="main">
        <h1 className="todoTitle">To do List</h1>
        <AddTask handleCallback={(value) => handleCallback(value)} />{" "}
        {/*callback called to save the input*/}
        <Tasks tasks={task} />
      </div>
    </div>
  );
}

component 2

class AddTask extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      inputValue: "",
    };
  }

  handleChange(e) {
    const { value } = e.target;

    this.setState({
      inputValue: value,
    });
  }

  handleClick() {
    const { inputValue } = this.state;
    if (inputValue !== "") {
      this.props.handleCallback(inputValue); // send value of event OnChange
      this.setState({
        inputValue: "",
      });
    }
  }

  handleKey(e) {
    const { inputValue } = this.state;
    if (e.keyCode === 13 && inputValue !== "") {
      this.props.handleCallback(inputValue); //event for key enter
      this.setState({
        inputValue: "",
      });
    }
  }

  render() {
    const { inputValue } = this.state;

    return (
      <div className="tasks">
        <input
          className="inputTask" //capturo el valor del input con el evento onchange
          type="text"
          placeholder="Ingresar tarea"
          value={inputValue}
          onChange={(e) => this.handleChange(e)}
          onKeyDown={(e) => this.handleKey(e)}
        />

        <button className="addTask" onClick={() => this.handleClick()}>
          Agregar
        </button>
      </div>
    );
  }
}

export default AddTask;

component 3

import Task from "../Task";
import "./style.scss";

export default function Tasks({ tasks }) {
  return (
    <div className="taskWrapper">
      <ul className="listWrapper">
        {tasks.map((task, key) => {
          //map the tasks and send props to Task
          return (
            <div>
              <Task name={task} key={key} id={key} />
            </div>
          );
        })}
      </ul>
    </div>
  );
}

component 4
I try to perform a deletion function with a filter but I can’t do it.

    export default function Task({ name, id }) {
  const (task, setTask) = useState(());
  const (done, setDone) = useState(false); // toggle for mark the tasks
  function handleClick() {
    if (done) {
      setDone(false);
    } else {
      setDone(true);
    }
  }

  function deleteClick(id) {
    const updateTask = name.filter((task) => name.id !== id);
    setTask(updateTask);
  }

  return (
    <>
      <div className="mainTask">
        <li onClick={handleClick}>
          {done ? (
            <span className="done">{name}</span>
          ) : (
            <span className="toDo">{name}</span>
          )}
        </li>
        <button onClick={deleteClick} className="deleteTask">
          ×
        </button>
      </div>
    </>
  );
}

reactjs – My React app enters into an endless loop once I press the button

I working on a little web app using the React and the Axios.

When the app first loads itself, it looks fine in my eyes.

But if I press the button, it will enter into some kind of endless loop for it just keeps acting like the user is constantly pressing the button over and over. The only way to to stop it, is to refresh the page.

I am not sure why it’s doing it. Right now it is just using test data because I’m trying to reduce the complexity to see if I can figure out what’s causing the error.

But so far, I can’t figure it out.

Here is my simple code:

import React from 'react';
import axios from 'axios';

export default class ThoughtDeducer extends React.PureComponent {

constructor(props) {
    super(props);
    this.state = {
        thoughts: "I am not here"
    };

}

shareYourThoughts = () => {
    var test = "I am in here";
    return axios.put("/sendto/api/saveThoughts", JSON.stringify(test), {
        headers: { 'Content-Type': 'application/json' }
    }).then((r) => {
        this.setState({...this.state, ...{thoughts: test}
        });

    })
}


render() {
    const { thoughts } = this.state;
    return (
       
        <div>
            <button onClick={this.shareYourThoughts}>Share Your Thoughts</button>;
            <div>{ thoughts }</div>
        </div>

    );

}

}

reactjs – React global functions that modifies DOM

I am creating a dashboard in React right
but I am always struggeling to globally make a function available that will show something on the DOM.

For example I would like to create a showModal() function that will show a modal, duhn..
This is a little example:

const {showModal} = useModal();

const cancelFunction = () => {...}
const successFunction = () => {...}

return(<button onClick={() => {showModal(title, description, cancelFunction, successFunction)}}/>)

But currently I think I am doing it in a bad way or very unclear..
And I think there is a better way of doing this.

This is my current setup:
https://hastebin.com/xuzivolijo.typescript

Then I am providing the ModalProvider in my root of my project
useGlobalState is just what is says: a state that is global. Just what redux or contexts do
Only in a state way.

I hope someone can explain me a best practice for doing this. Thanks.

reactjs – Call React Custom Hook from a function

I am writing a hook to get data from server (calling an API). This hook should be called when a component is loaded and also when a button is clicked where the button exists in the same component. (Actually I am using this in ReactNative where I want the hook to be called on refresh, but to make it simple I am taking button here)

Here is my hook:

export default function useApi() {
    const (data, setData) = useState({ loading: false, error: null, data: undefined });

    useEffect(() => {
        callApi();
    }, ());

    const callApi = async () => {
        let response;
        try {
            setData({ ...data, loading: true });
            response = await axios.get("url");
        } catch (e) {
            setData({ ...data, loading: false, error: e });
        } finally {
            setData({
                    ...data,
                    loading: false,
                    data: response.data,
                });
        }
    };
    return data;
};

My Component:

export default function SpecialComponent() {

const { loading, error, data } = useApi();

const getData = () => {
 //I need to get data using the hook here.
};

return (
   <div>
       { !loading && 
          <div>
              <div>{JSON.stringify(data)}</div> 
              <Button onClick={getData}>Got latest data</Button>
          </div>
       }

       { loading && <div>Loading...</div> }
   </div>
);

}

I thought about useEffect but again same problem. I am not sure if it is a right pattern to call a hook from useEffect.

Any help is highly appreciated.

reactjs – Where should I put/handle periodic data updates in React?

I’m following the guide in https://reactjs.org/docs/thinking-in-react.html which makes sense for data that I request and update on a filter.

However, I want to have some sort of general synchronization job in the background that polls and updates an SQLite database periodically.

The question I have is if the SQLite database has detected that there was an update, how do I signal to a list component that it needs to refresh itself?

Notes:

I am thinking if it was in a context it will trigger a re-render of every component underneath it which may be problematic if I have something like a data entry form since a re-render will cause my focus to be lost

In vue land we have emit to emit custom events, but I don’t see anything like that in the API guide for React

Another approach I was thinking of was to useReducer, but it didn’t pan out on the context because it will also cause a re-render just like useState

Then I thought of having the reducer on the filtered table component but then I don’t know how to trigger it from the context.

DreamProxies - Cheapest USA Elite Private Proxies 100 Cheap USA Private Proxies Buy 200 Cheap USA Private Proxies 400 Best Private Proxies Cheap 1000 USA Private Proxies 2000 USA Private Proxies 5000 Cheap USA Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Best Quality USA Private Proxies