• Как вывести объекты из localStorage в React?

    @Dani777
    i see some problems with tags:
    function App () {
      const [state,setState] = React.useState({
        user: '',
        rememberMe: false
      })
    
      const ref = useRef(null)
     
      const handleChange = (event) => {
        const input = event.target;
        const value = input.type === 'checkbox' ? input.checked : input.value;
     
        setState(Object.assign({}, state, {[input.name]: value }));
      };
     
     
      localStorage.setItem('foo', 'foo')
      const handleFormSubmit = () => {
        const { user, rememberMe } = state;
        localStorage.setItem('rememberMe', JSON.stringify(rememberMe));
    
        if (rememberMe) {
          localStorage.setItem('user', JSON.stringify(user));
        } else {
          localStorage.setItem('user', '');
        }
      };
      
       useEffect( () => {
        const rememberMe = localStorage.getItem('rememberMe') === 'true';
        const user = rememberMe ? JSON.parse(localStorage.getItem('user')) : '';
        setState({ user, rememberMe });
      },[])
    
     
        return (
          <form onSubmit={handleFormSubmit} ref={ref}>
            <label>
              User: <input name="user" value={state.user} onChange={handleChange}/>
            </label>
            <label>
              <input name="rememberMe" checked={state.rememberMe} onChange={handleChange} type="checkbox"/> Remember me
            </label>
            <button type="submit">Sign In</button>
          </form>
        );
    }
     
     
    
    
    export default App;
  • Как вывести объекты из localStorage в React?

    @Dani777
    Hi everyone if somebody was looking for React LocalStorage with functional components you need to write this code which writed below:

    function App () {
    const [state,setState] = React.useState({
    user: '',
    rememberMe: false
    })

    const ref = useRef(null)

    const handleChange = (event) => {
    const input = event.target;
    const value = input.type === 'checkbox' ? input.checked : input.value;

    setState(Object.assign({}, state, {[input.name]: value }));
    };


    localStorage.setItem('foo', 'foo')
    const handleFormSubmit = () => {
    const { user, rememberMe } = state;
    localStorage.setItem('rememberMe', JSON.stringify(rememberMe));

    if (rememberMe) {
    localStorage.setItem('user', JSON.stringify(user));
    } else {
    localStorage.setItem('user', '');
    }
    };

    useEffect( () => {
    const rememberMe = localStorage.getItem('rememberMe') === 'true';
    const user = rememberMe ? JSON.parse(localStorage.getItem('user')) : '';
    setState({ user, rememberMe });
    },[])


    return (


    User:


    Remember me

    Sign In

    );
    }



    export default App;
  • Как реализовать в Java возврат к началу класса?

    @Dani777
    Scanner RepetitionMethod = new Scanner(System.in);

    while (true) {

    System.out.print("Would you like to explore the garage? (yes or no):");
    String quest = RepetitionMethod.nextLine();

    if (quest.equals("yes")||quest.equals("y")||quest.equals("1")) {
    System.out.println("You see: Tv, Books, Car ");
    break;
    } else if (quest.equals("no")||quest.equals("n")||quest.equals("0")) {
    System.out.println("You not see ");
    break;

    }else{
    System.out.println("Error you need write (yes or no)");
    System.out.println("Try again!");

    }

    }
    RepetitionMethod.close();
    }
    }