“bereaksi mengatur cookie” Kode Jawaban

bereaksi mengatur cookie

import Cookies from 'universal-cookie';
const cookies = new Cookies();
cookies.set('myCat', 'Pacman', { path: '/' });
console.log(cookies.get('myCat')); // Pacman
Abdullah Al Muzaki

Atur cookie di reactjs

npm install react-cookie
        or 
yarn add react-cookie

import { useCookies } from 'react-cookie'

const SignInComponent = () => {


const [cookies, setCookie] = useCookies(['access_token', 'refresh_token'])

async function onSubmit(values) {
    const response = await getOauthResponse(values);

    let expires = new Date()
    expires.setTime(expires.getTime() + (response.data.expires_in * 1000))
    setCookie('access_token', response.data.access_token, { path: '/',  expires})
    setCookie('refresh_token', response.data.refresh_token, {path: '/', expires})


}


}
30_Savaliya Denish

cara menggunakan cookie di react js

const [cookies, setCookie, removeCookie] = useCookies(['cookie-name']);
Alert Armadillo

cara menggunakan cookie dalam komponen kelas reaksi

import React, { Component } from "react";
import { instanceOf } from "prop-types";
import { withCookies, Cookies } from "react-cookie";

class App extends Component {
  static propTypes = {
    cookies: instanceOf(Cookies).isRequired
  };

  state = {
    user: this.props.cookies.get("user") || ""
  };

  handleCookie = () => {
    const { cookies } = this.props;
    cookies.set("user", "gowtham", { path: "/" }); // setting the cookie
    this.setState({ user: cookies.get("user") });
  };

  render() {
    const { user } = this.state;
    return (
      <div className="App">
        <h1>React cookies</h1>
        {user && <p>{user}</p>}
        <button onClick={this.handleCookie}>Set Cookie</button>
      </div>
    );
  }
}

export default withCookies(App);
Healthy Hoopoe

bereaksi cookie

// server.jsrequire('@babel/register'); const express = require('express');const serverMiddleware = require('./src/server').default;const cookiesMiddleware = require('universal-cookie-express'); const app = express(); app  .use('/assets', express.static('dist'))  .use(cookiesMiddleware())  .use(serverMiddleware); app.listen(8080, function() {  console.log('Listening on 8080...');});
Fantastic Fowl

Jawaban yang mirip dengan “bereaksi mengatur cookie”

Pertanyaan yang mirip dengan “bereaksi mengatur cookie”

Lebih banyak jawaban terkait untuk “bereaksi mengatur cookie” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya