Skip to content
TheChatArchiveThe Chat Archive
Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)Hugging Face OpenAssistant Conversations (oasst2)

How do I store and manage cookies in React?

In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
  1. User

    How do I store and manage cookies in React?

  2. Assistant

    There are many ways to store and manage cookies in React. You could for example use the library react-cookie like so:

    // Root.jsx
    import React from 'react';
    import App from './App';
    import { CookiesProvider } from 'react-cookie';
    
    export default function Root() {
      return (
        <CookiesProvider>
          <App />
        </CookiesProvider>
      );
    }
    
    // App.jsx
    import React from 'react';
    import { useCookies } from 'react-cookie';
    
    import NameForm from './NameForm';
    
    function App() {
      const [cookies, setCookie] = useCookies(['name']);
    
      function onChange(newName) {
        setCookie('name', newName, { path: '/' });
      }
    
      return (
        <div>
          <NameForm name={cookies.name} onChange={onChange} />
          {cookies.name && <h1>Hello {cookies.name}!</h1>}
        </div>
      );
    }
    
    export default App;
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.