electron(nodejs)上で特定のファイルをtailする
tailライブラリを使用する。
https://github.com/lucagrulla/node-tail
$ yarn add tail
App.tsx
import React, { useEffect, useState } from 'react'
import { render } from 'react-dom'
import { Tail } from 'tail'
const tail = new Tail('file-path')
const App = () => {
let [texts, setTexts] = useState<string[]>([])
useEffect(() => {
tail.on('line', (data : string) => {
texts = [...texts, data]
setTexts(texts)
})
return () => {
tail.unwatch()
}
}, [])
return (
<>
{
texts.map((text, index) => {
return (
<div key={index}>{text}</div>
)
})
}
</>
)
}