Use-prompt - React promise-based user prompts

Overview

DTS React w/ Storybook User Guide

Congrats! You just saved yourself hours of work by bootstrapping this project with DTS. Let’s get you oriented with what’s here and how to use it.

This DTS setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use create-react-app, razzle, nextjs, gatsby, or react-static.

If you’re new to TypeScript and React, checkout this handy cheatsheet

Commands

DTS scaffolds your new library inside /src, and also sets up a Vite-based playground for it inside /example.

The recommended workflow is to run DTS in one terminal:

npm start # or yarn start

This builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.

Then run either Storybook or the example playground:

Storybook

Run inside another terminal:

yarn storybook

This loads the stories from ./stories.

NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.

Example

Then run the example inside another:

cd example
npm i # or yarn to install dependencies
npm start # or yarn start

The default example imports and live reloads whatever is in /dist, so if you are seeing an out of date component, make sure DTS is running in watch mode like we recommend above.

To do a one-off build, use npm run build or yarn build.

To run tests, use npm test or yarn test.

Configuration

Code quality is set up for you with prettier, husky, and lint-staged. Adjust the respective fields in package.json accordingly.

Jest

Jest tests are set up to run with npm test or yarn test.

Bundle analysis

Calculates the real cost of your library using size-limit with npm run size and visulize it with npm run analyze.

Setup Files

This is the folder structure we set up for you:

/example
  index.html
  index.tsx       # test your component here in a demo app
  package.json
  tsconfig.json
/src
  index.tsx       # EDIT THIS
/test
  index.test.tsx  # EDIT THIS
/stories
  Thing.stories.tsx # EDIT THIS
/.storybook
  main.js
  preview.js
.gitignore
package.json
README.md         # EDIT THIS
tsconfig.json

React Testing Library

We do not set up react-testing-library for you yet, we welcome contributions and documentation on this.

Rollup

DTS uses Rollup as a bundler and generates multiple rollup configs for various module formats and build settings. See Optimizations for details.

TypeScript

tsconfig.json is set up to interpret dom and esnext types, as well as react for jsx. Adjust according to your needs.

Continuous Integration

GitHub Actions

Two actions are added by default:

  • main which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
  • size which comments cost comparison of your library on every pull request using size-limit

Optimizations

Please see the main dts optimizations docs. In particular, know that you can take advantage of development-only optimizations:

// ./types/index.d.ts
declare var __DEV__: boolean;

// inside your code...
if (__DEV__) {
  console.log('foo');
}

You can also choose to install and use invariant and warning functions.

Module Formats

CJS, ESModules, and UMD module formats are supported.

The appropriate paths are configured in package.json and dist/index.js accordingly. Please report if any issues are found.

Deploying the Example Playground

The Playground is just a simple Vite app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for manually deploying with the Netlify CLI (npm i -g netlify-cli):

cd example # if not already in the example folder
npm run build # builds to dist
netlify deploy # deploy the dist folder

Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:

netlify init
# build command: yarn build && cd example && yarn && yarn build
# directory to deploy: example/dist
# pick yes for netlify.toml

Named Exports

Per Palmer Group guidelines, always use named exports. Code split inside your React app instead of your React library.

Including Styles

There are many ways to ship styles, including with CSS-in-JS. DTS has no opinion on this, configure how you like.

For vanilla CSS, you can include it at the root directory and add it to the files section in your package.json, so that it can be imported separately by your users and run through their bundler's loader.

Publishing to NPM

We recommend using np.

Usage with Lerna

When creating a new package with DTS within a project set up with Lerna, you might encounter a Cannot resolve dependency error when trying to run the example project. To fix that you will need to make changes to the package.json file inside the example directory.

The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's package.json might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.

Change the alias to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.

   "alias": {
-    "react": "../node_modules/react",
-    "react-dom": "../node_modules/react-dom"
+    "react": "../../../node_modules/react",
+    "react-dom": "../../../node_modules/react-dom"
   },

An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. However, that might cause other problems.

You might also like...
Fully customizable, easy to use checkbox with flexible component by React Native on Android and iOS
Fully customizable, easy to use checkbox with flexible component by React Native on Android and iOS

Installation Add the dependency: npm i react-native-checkbox-flex Peer Dependencies IMPORTANT! You need install them "@freakycoder/react-native-bounce

A simple to use interval timer for boxing
A simple to use interval timer for boxing

Simple Boxtimer A simple timer for boxing. Written with react native, works on android and the web. Download Google Playstore APK from Releases Progre

Fully customizable, animated & easy to use radio button group
Fully customizable, animated & easy to use radio button group

Installation Add the dependency: npm i react-native-animated-radio-button-group Peer Dependencies IMPORTANT! You need install them "@freakycoder/react

React Native ssl pinning and cookies handling based on okhttp3 on (Android). and AFNetworking on (iOS)

react-native-ssl-pinning React-Native ssl pinning & public key pinning using OkHttp 3 in Android, and AFNetworking on iOS. NOTES: for RN 0.60.0 or lat

Firebase incoming call notifications for React Native based applications.
Firebase incoming call notifications for React Native based applications.

Android Call Notifications App (React Native) Banner Notifications FullScreen Notifications Prerequisites for project Create a firebase project from f

Alarm clock functionality for react native ios and android using react-native-push-notification and react-native-community/async-storage
Alarm clock functionality for react native ios and android using react-native-push-notification and react-native-community/async-storage

react-native-simple-alarm Alarm clock functionality for react native ios and android built using react-native-push-notification and react-native-commu

React Native CallKit utilises a brand new iOS 10 framework CallKit to make the life easier for VoIP developers using React Native.

React Native CallKit utilises a brand new iOS 10 framework CallKit to make the life easier for VoIP developers using React Native.

React-firebase-mui-insta-reels - React Firebase Material-UI insta reels app
React-firebase-mui-insta-reels - React Firebase Material-UI insta reels app

React Firebase Material-UI insta reels app Website link : here P.S :- Open the w

React-native-wordle - A simple re-implementation of wordle using react native

react native wordle A simple re-implementation of wordle. guess the randomly cho

Releases(v1.1.0)
Owner
Jonathan Newman
Typescript and web app aficionado from Houston, I write stuff that makes the web do things.
Jonathan Newman
A Web project built using ReactJs that asks the user a few questions, then based on the answers provided we suggest him some games that might be suitable for him.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 5 Aug 5, 2022
React Native Firebase Authentication Starter, manage user authentication in React Native app with firebase

Sign up and sign in screens for mobile using React Native. This is an example of how to use Firebase Authentication in React Native application, how to let users create an account or log in to an existing account.

Maor 14 Sep 8, 2022
React Native module bridge to obtain information about the user’s home cellular service provider,

React Native Carrier Info React Native module bridge to obtain information about the user’s home cellular service provider. Makes use of the following

React Native WebRTC 79 Jun 12, 2022
Creating secure routes and saving user information in SecureStore

React Native, sistema de login social nativo usando uma conta do Google Primeiro passo clonar o repositório git clone [email protected]:r-santtos/Stu

Ricardo Santos 1 Dec 11, 2021
A barcode scanner component for react native - not maintained anymore - use react-native-camera

react-native-barcodescanner - not maintained anymore - use react-native-camera Version 0.4.0 of react-native-camera includes barcode scanning for andr

Idea Creation / E-GUMA 537 Sep 17, 2022
Easy to use CoreNFC for React Native

React Native NFC for iOS ⚠️ Apple CoreNFC is only available for iOS11 on iPhone 7 and iPhone 7 Plus devices. It does not seems to be available on simu

Paul Chobert 59 Jun 11, 2022
📲 Communicate with nearby devices using Bluetooth, BLE, WiFi and near-ultrasonic audio. Broadcast and receive small payloads (like strings) using the easy-to-use React Native API!

react-native-google-nearby-messages An async Google Nearby Messages API Wrapper for React Native (Android & iOS), supporting autolinking, custom disco

Marc Rousavy 142 Sep 19, 2022
Use ESBuild to make your React Native code bundle faster.

metro-minify-esbuild Use ESBuild to make your React Native code bundle faster. Metro Bundler (used for React Native, Instagram, Internal Facebook) all

Evan Bacon 109 Sep 18, 2022
A wrapper of Lock to use with React Native (iOS & Android)

A wrapper of Lock to use with React Native (iOS & Android)

Auth0 278 May 18, 2022
Simple, best and easy to use radio buttons for react native apps.

React Native Radio Buttons Group Simple, best and easy to use radio buttons for react native apps. Getting Started Just a sneak peek (lots more can be

Thakur Ballary 148 Sep 20, 2022