npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-ollama

v0.2.2

Published

Integrate Ollama into your React application

Readme

react-ollama

Integrate Ollama into your React application.

react-ollama is a simple wrapper library around ollama-js, providing React hooks to interact with Ollama in React applications in a more convenient way.

| Statements | Branches | Functions | Lines | |-----------|----------|-----------|-------| | Statements | Branches | Functions | Lines |

Install

npm i react-ollama

Features

  • ⚛️ React hooks to interact with Ollama🦙
  • 🤝 Fully compatible with browser environment (even static sites!)
  • 🌐 SSR support
  • 🟦 100% TypeScript
  • ✅ Supports all Ollama API endpoints

Usage

react-ollama provides the following functions to interact with Ollama:

  • useGenerate - React hook to generate a response for a given prompt with a provided model.
import { useGenerate } from 'react-ollama';

export const GenerateExample = () => {
  const { answer, sendMessage } = useGenerate('llama3.2');

  const handleClick = () => {
    sendMessage({
      prompt: 'What is the meaning of life?',
      stream: true
    });
  };

  return (
    <div>
      <button onClick={handleClick}>Generate</button>
      <p>{answer}</p>
    </div>
  );
};
  • useChat - React hook to interact with Ollama in a chat-like interface.
import { useChat } from 'react-ollama';

export const ChatExample = () => {
  const { answer, sendMessage } = useChat('llama3.2');

  const handleClick = () => {
    sendMessage({
      messages: [
        {
          role: 'user',
          content: 'You are an expert philosopher. Give me an answer in 20 words or less.'
        },
        {
          role: 'user',
          content: 'Now, tell me: what is the meaning of life?'
        }
      ],
      stream: true
    });
  };

  return (
    <div>
      <button onClick={handleClick}>Chat</button>
      <p>{answer}</p>
    </div>
  );
};
  • reactOllama - function to interact with the Ollama in a more flexible way. Supports Server Components and all of the Ollama API endpoints. Provides the following methods:

    • generate - Generate a response for a given prompt with a provided model.
    • chat - Generate the next message in a chat with a provided model.
    • pullModel - Downloads a model from the Ollama library.
    • pushModel - Uploads a model to the Ollama library.
    • createModel - Creates a new model from a base model.
    • deleteModel - Deletes a model and it's data.
    • copyModel - Copies a model to create a new model with a different name.
    • listModels - Lists all available local models.
    • showModel - Shows metadata of a specific model.
    • listRunningModels - Lists all currently running models.
    • generateEmbed - Generates an embed from a model.
    • abort - Aborts all streamed generations currently running.
import { isAbortable, reactOllama } from 'react-ollama';

export const ServerReactOllama = async () => {
  const { generate, listRunningModels, listModels } = reactOllama();

  const generateResponse = await generate({
    model: 'llama3.2',
    prompt: 'What is the meaning of life?',
    stream: false
  });

  const content =
    !isAbortable(generateResponse) && generateResponse ? generateResponse.response : '';

  const runningModels = await listRunningModels();
  const models = await listModels();

  return (
    <div>
      <div>{content}</div>
      {runningModels.map((m) => (
        <div key={m.model}>
          <h1>{m.name}</h1>
        </div>
      ))}
      {models.map((m) => (
        <div key={m.model}>
          <h1>{m.name}</h1>
        </div>
      ))}
    </div>
  );
};

react-ollama comes in with default Ollama client, but you are free to provide your own clients:

import { Ollama } from 'react-ollama';

export const ollamaInstance = new Ollama({
  host: 'http://localhost:8000'
});
import { ollamaInstance } from './ollamaInstance';
import { useGenerate } from 'react-ollama';

export CustomOllamaComponent = () => {
  const { answer, sendMessage } = useGenerate('llama3.2', ollamaInstance);

  const handleClick = () => {
    sendMessage({
      prompt: 'What is the meaning of life?',
      stream: true
    });
  };

  return (
    <div>
      <button onClick={handleClick}>Generate</button>
      <p>{answer}</p>
    </div>
  );
};

Contributing

Any contributions are welcome! Feel free to open an issue or a pull request here:

Credits

  • Ollama for creating a great tool to run LLMs locally.
  • ollama-js for JS library to interact with Ollama and making this possible.