Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-liff

epaew814MIT2.1.0TypeScript support: included

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

react, react-component, liff, line

readme

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

changelog

Unreleased

Features

Bug Fixes

BREAKING CHANGES

Others

v2.1.0

BREAKING CHANGES

  • #554
    • Now, react-liff package is published as native ESM.

Others

  • #492
    • Tests with @line/liff@2.21.
  • #553
    • Use npm as package manager.

v2.0.0

Features

  • #455
    • Add plugins callback to LiffProvider optional props to use LIFF plugins.

Bug Fixes

  • #424
    • LiffProvider was not passing option liffConfig.withLoginOnExternalBrowser to the LIFF SDK.
  • #456
    • customLogin() was not passing option loginConfig.redirectUri to the original login().

BREAKING CHANGES

  • #452 #454
  • #453 #473
    • Dropped supporting @line/liff version 2.19.0 or earlier.
    • Relax the upper limit of @line/liff version.
  • #460
    • Rename the value of useLiff() returns: ready => isReady.
  • #455
    • Remove stubEnabled from LiffProvider props.
    • You can use LIFF plugin @line/liff-mock instead.
  • #463
    • Now, @line/liff is an optional peer dependency for react-liff.
    • You need to add @line/liff to your app's dependencies yourself.

Others

  • #458
    • Refactoring: Remove type generics: is overspec.
  • #459
    • Refactoring: Move and split src/Context.tsx
  • #461
    • Update test workflow to send test coverage to Code Climate.

1.6.0

Features

Others

  • #448
    • mv __tests__/*.test.tsx to src/.

1.5.1

Features

  • #403
    • Started supporting @line/liff@2.19.

1.5.0

Features

  • #358
    • Started supporting @line/liff@2.18.

Others

  • #366
    • Update prettier configuration.

1.4.0

Features

  • #347
    • Started supporting @line/liff@2.17.

1.3.0

Features

  • #336
    • Started supporting @line/liff version from 2.14.x to 2.16.x.

Others

  • #338 #339
    • Upgrade outdated devDependencies

1.2.1

Bug Fixes

  • #334
    • Import liff object from default export of '@line/liff'. Thanks for @malparty :)

1.2.0

BREAKING CHANGES

  • #306
    • For TypeScript user only: LiffContext returned the error as LiffError | undefined, but now it returns as unknown (including undefined).

1.1.0

Others

  • #297 Started supporting @line/liff@2.13.

1.0.0

BREAKING CHANGES

  • #280
    • Started supporting @line/liff version 2.11.x and 2.12.0.
    • Dropped supporting @line/liff version 2.8.x or earlier.
      • Version 2.9.x and 2.10.x will continue to be supported.
  • #281
    • Removed deprecated loggedIn function in LiffContext.

Others

  • CI enhancements.
  • Updated some development dependencies.

0.9.0

Others

  • #278 Started supporting @line/liff@2.10.

0.8.0

Others

  • #232 Started supporting @line/liff@2.9.

0.7.3

Others

  • #213 Started supporting @line/liff@2.8.

0.7.2

Others

  • #204 Started supporting @line/liff@2.7.

0.7.1

Others

  • #169 Update .eslintrc to use @epaew/eslint-config and fix ESLint errors.
  • #186 Refactoring: Introduce the new jsx transform.
  • #191 Started supporting @line/liff@2.6.

0.7.0

Others

0.6.2

Bug Fixes

  • #120 Get compatible w/ @line/liff@2.4.1.

0.6.1

Bug Fixes

  • #113 Fixup the version range of @line/liff dependency.

0.6.0

Bug Fixes

  • #107 Fixup type error with @line/liff@2.4.0.

BREAKING CHANGES

  • #109 Rename loggedIn in LiffContext to isLoggedIn.

0.5.0

Features

  • #45 Add @line/liff as optionalDependency.

0.4.2

Others

  • #23 Change the module specification of tsconfig.json: from es2015 to commonjs.

0.4.1

Others

  • #21 Change the target version of tsconfig.json: from ES2019 to ES2015.

0.4.0

Features

  • #14 Update the stub implementation: make login state updatable.
  • #15 Add loggedIn state in LiffContext

0.3.0

Features

  • #10
    • Add new export createLiffContext<T>(), for TypeScript user, now you can overload the context type definition of liff object.
    • Define propTypes of LiffProvider, for non-TypeScript user.

Others

  • #10
    • Split the codes.
    • Remove optional dependency of liff-type.

0.2.0

Features

  • #2 Add export LiffConsumer
  • #4 Add flag to check "is liff ready?"

Others

  • #2 Move dependency of package liff-type from peer to optional
  • #4 Add tests
  • #5 Update README.md and add CHANGELOG.md

0.1.0

Initial release