test: refactor test:demo script into demo/*/test.sh

This commit is contained in:
Yang Jun
2024-08-29 01:30:25 +08:00
committed by Jun Yang
parent da516a4fd6
commit 62bb20e433
48 changed files with 3018 additions and 23043 deletions
+35
View File
@@ -0,0 +1,35 @@
import { useState, useLayoutEffect } from 'react';
import './App.css';
import logo from './logo.svg';
import showingClickTimes from './views/showing-click-times.liquid?raw';
import { engine } from './engine';
import { Context } from './Context';
import { ClickButton } from './ClickButton';
const tpl = engine.parse(showingClickTimes)
export function App() {
const [state, setState] = useState({
logo,
name: 'liquid',
clickCount: 0,
html: ''
});
useLayoutEffect(() => {
engine.render(tpl, state).then(html => setState({...state, html}))
}, [state.clickCount])
return (
<div className="App">
<div dangerouslySetInnerHTML={{__html: state.html}}></div>
<Context.Provider
value={{
count: () => setState({...state, clickCount: state.clickCount + 1})
}}
>
<ClickButton/>
</Context.Provider>
</div>
);
}