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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-liff-v2

v0.7.2

Published

A react context provider for LIFF (LINE Front-end Framework)

Downloads

3

Readme

react-liff

npm version Build Status Maintainability

A react context provider for LIFF (LINE Front-end Framework)

Requirements

  • React v16.14 or later
    • React Native is not supported.
  • LIFF SDK version 2

Getting started

When you use NPM version of LIFF SDK (Recommended)

  1. Create your React application development environment.
    • e.g. npx create-react-app app-name
  2. Add react-liff to your app dependencies.
    npm i --save @line/liff react-liff
    # or
    yarn add @line/liff react-liff
  3. Import react-liff to your app and use it!
    • An example of src/App.js
      import React, { useEffect, useState } from 'react';
      import { useLiff } from 'react-liff';
      
      import './App.css';
      
      const App = () => {
        const [displayName, setDisplayName] = useState('');
        const { error, liff, isLoggedIn, ready } = useLiff();
      
        useEffect(() => {
          if (!isLoggedIn) return;
      
          (async () => {
            const profile = await liff.getProfile();
            setDisplayName(profile.displayName);
          })();
        }, [liff, isLoggedIn]);
      
        const showDisplayName = () => {
          if (error) return <p>Something is wrong.</p>;
          if (!ready) return <p>Loading...</p>;
      
          if (!isLoggedIn) {
            return <button className="App-button" onClick={liff.login}>Login</button>;
          }
          return (
            <>
              <p>Welcome to the react-liff demo app, {displayName}!</p>
              <button className="App-button" onClick={liff.logout}>Logout</button>
            </>
          );
        }
      
        return (
          <div className="App">
            <header className="App-header">{showDisplayName()}</header>
          </div>
        );
      }
      
      export default App;
    • An example of src/index.js
      import React from 'react';
      import ReactDOM from 'react-dom';
      import { LiffProvider } from 'react-liff';
      
      import './index.css';
      import App from './App';
      
      const liffId = process.env.REACT_APP_LINE_LIFF_ID;
      const stubEnabled = process.env.NODE_ENV !== 'production';
      
      ReactDOM.render(
        <React.StrictMode>
          <LiffProvider liffId={liffId} stubEnabled={stubEnabled}>
            <App />
          </LiffProvider>
        </React.StrictMode>,
        document.getElementById('root')
      );

When you use CDN version of LIFF SDK

  1. Create your React application development environment.
    • e.g. npx create-react-app app-name
  2. Add react-liff to your app dependencies.
    npm i --save react-liff
    # or
    yarn add react-liff
  3. Update index.html to load LIFF SDK
    • https://developers.line.biz/en/docs/liff/developing-liff-apps/#developing-a-liff-app
      +    <script defer charset="utf-8" src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
  4. Import react-liff to your app and use it!

API

LiffProvider props

  • liffId: string, required
    • The ID of your LIFF application.
    • When you using stubs, you can specify empty string.
  • stubEnabled: boolean | Object | undefined, optional
    • false or undefined: Provider uses LIFF SDK (for Production).
    • true: Provider uses stubs defined in library.
    • Object: Provider uses the stubs you specified here.

LiffConsumer / useLiff return values

  • error: LiffError | undefined
    • Returns LiffError if liff.init() failed.
  • isLoggedIn: boolean
    • Returns whether the user is logged in.
  • ready: boolean
    • Returns true after liff.init() or stub setup has successfully completed.
  • liff: Liff
    • Returns liff object.

CHANGELOG

CHANGELOG

LICENSE

MIT