React Ink首頁、文檔和下載- 面向命令行應用的React – 程式开发

Ink 是支持使用React 來構建命令行應用程序的庫——與React 在瀏覽器中提供的基於組件的UI 構建體驗一樣。只是InK 面向命令行應用程序。

因此Ink 其實就是React 渲染器,將React 組件樹轉成字符串,然後輸出到終端上。

安裝


npm install ink react

使用


import React, {useState, useEffect} from 'react';
import {render, Text} from 'ink';

const Counter = () => {
	const [counter, setCounter] = useState(0);

	useEffect(() => {
		const timer = setInterval(() => {
			setCounter(previousCounter => previousCounter + 1);
		}, 100);

		return () => {
			clearInterval(timer);
		};
	}, []);

	return <Text color="green">{counter} tests passed</Text>;
};

render(<Counter />);

#React #Ink首頁文檔和下載 #面向命令行應用的React #程式开发

Leave a Reply

Your email address will not be published. Required fields are marked *