Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-liff

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-liff

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

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-liff

npm version Build Status Maintainability

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

Requirements

  • React v18.0 or later
    • React Native is not supported.
  • LIFF SDK version >=2.19.1

Getting started

  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, isLoggedIn, isReady, liff } = 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 (!isReady) 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;
      
      ReactDOM.render(
        <React.StrictMode>
          <LiffProvider liffId={liffId}>
            <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
  4. Import react-liff to your app and use it!

API

LiffProvider props

  • liffId: string, required
    • The ID of your LIFF application.
  • withLoginOnExternalBrowser: boolean, optional
  • plugins: Array<LiffPlugin | [LiffPlugin, LiffPluginOption]>, optional
    • List of LIFF plugin instances.
    • If you need to pass option to plugin, you can use the list of tuple [pluginInstance, pluginOption].
  • callback: (liff: Liff) => Promise<void>, optional
    • Callback function that fires after liff.init() has been succeeded.

LiffConsumer / useLiff return values

  • error: unknown (is LiffError | undefined in many cases)
    • Returns an error if liff.init() was failed.
  • isLoggedIn: boolean
    • Returns whether the user is logged in.
  • isReady: boolean
    • Returns true after liff.init() has successfully completed. Otherwise, returns false.
  • liff: Liff
    • Returns liff object.

CHANGELOG

CHANGELOG

LICENSE

MIT

Keywords

FAQs

Package last updated on 26 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc