TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to write PureScript react components to replace JavaScript

99 pointsby JacksonGarietyalmost 5 years ago

13 comments

chvidalmost 5 years ago
This is the corresponding code written in React using hooks:<p><pre><code> export const Counter = ({label, counterType, onClick}) =&gt; { const [counter, setCounter] = useState(0); return ( &lt;button onClick={() =&gt; { counterType == &quot;Increment&quot; &amp;&amp; setCounter(counter + 1); counterType == &quot;Decrement&quot; &amp;&amp; setCounter(counter - 1); onClick &amp;&amp; onClick(); }}&gt; {label}: {counter} &lt;&#x2F;button&gt; ); } </code></pre> I think the case for PureScript React would be more convincing if the code you ended up with was loosely as concise as the above.
评论 #23638545 未加载
评论 #23638528 未加载
评论 #23637776 未加载
评论 #23637300 未加载
评论 #23638658 未加载
评论 #23638200 未加载
评论 #23637295 未加载
评论 #23642161 未加载
评论 #23637710 未加载
evanrelfalmost 5 years ago
You can also use React Hooks in PureScript with purescript-react-basic-hooks[1].<p>Or for a more native PureScript approach to single-page web apps, check out purescript-halogen[2] and purescript-halogen-hooks[3] (created by the author of this article).<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;spicydonuts&#x2F;purescript-react-basic-hooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;spicydonuts&#x2F;purescript-react-basic-hooks</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;purescript-halogen&#x2F;purescript-halogen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;purescript-halogen&#x2F;purescript-halogen</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;thomashoneyman&#x2F;purescript-halogen-hooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomashoneyman&#x2F;purescript-halogen-hooks</a>
quickthrower2almost 5 years ago
Is PureScript nice to use again? Tried it a year or two ago and it relied heavily on Bower and I had a hard time getting anything to work on Windows - lots of Bower errors and such. I tried it a few years ago and got it to work, but in that case getting Halogen to compile the most basic app just stuck the compiler into a freeze for minutes, so I gave up. But I am not shitting on PureScript, it looks like a fantastic way to develop JS apps, and I&#x27;d love to use it.
评论 #23638735 未加载
评论 #23637862 未加载
andrenthalmost 5 years ago
Not to hijack the thread, but I’ve recently learned that Purescript-Native has a Go target [1].<p>Does anyone have experience with this? How practical would it be to use this where one would otherwise use Go?<p>[1] <a href="https:&#x2F;&#x2F;discourse.purescript.org&#x2F;t&#x2F;purescript-native-can-now-target-golang&#x2F;878" rel="nofollow">https:&#x2F;&#x2F;discourse.purescript.org&#x2F;t&#x2F;purescript-native-can-now...</a>
azangrualmost 5 years ago
How is Purescript these days?<p>I haven&#x27;t heard many news from its ecosystem since Phil Freeman stepped down from its active development. Purescript by Example must be quite outdated by now? I know that Alex Kelley is still working on his set of tutorials &quot;Make the Leap from Javascript to Purescript&quot;[0]. Anything else interesting going on?<p>I feel like there was a lot of excitement about Purescript in around 2015-2016, but then it sort of died out?<p>0 - <a href="https:&#x2F;&#x2F;github.com&#x2F;adkelley&#x2F;javascript-to-purescript" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;adkelley&#x2F;javascript-to-purescript</a>
评论 #23641095 未加载
评论 #23640921 未加载
lightgreenalmost 5 years ago
&gt; JavaScript apps to PureScript &gt; Both companies have seen a dramatic drop in bugs in production.<p>I suspect if they migrated from JavaScript to TypeScript instead they would have seen the same dramatic drop in bugs, but also migrated much quicker and would be able to hire engineers easier, and development speed would have increased (because of much better tooling&#x2F;IDE&#x2F;interop).<p>I think PureScript is a very bright project, I even want to try it myself, but realistically, comparison to plain JavaScript is not the best benchmark.
oweqruiowealmost 5 years ago
How do they connect child components to parts of the application state in PureScript? I&#x27;m looking for a mechanism like react-redux&#x27;s `connect` function. Something that eliminates the need to pass state through the root component down to everything else.
michaelcampbellalmost 5 years ago
I admire his CLI approach to things, but this just seems dogmatic:<p><pre><code> echo -e &quot;\noutput\n.psc*\n.purs*\.spago&quot; &gt;&gt; .gitignore </code></pre> Sure, ok, saying &quot;add these entries to your .gitignore&quot; is too pedestrian?
评论 #23642817 未加载
fristysalmost 5 years ago
Holy shit that syntax looks disgusting. No way Jose.
Osirisalmost 5 years ago
The article says that PureScript helped them reduce bugs but fails to give any examples of how PureScript prevented bugs.<p>Looking at the examples, the code seems to function the same so it&#x27;s not obvious what problem is being solved that warrants teaching a whole dev team a new language.<p>In my experience, the vast majority of React app bugs are 1) state management, or 2) asynchronousisty. How does PureScript help to prevent those two classes of bugs?
评论 #23639191 未加载
BFattsalmost 5 years ago
Do we need another strongly typed language that compiles to JavaScript? If that&#x27;s so important, why don&#x27;t people use C&#x2F;C++ and compile that to WASM for best performance too? We&#x27;ve got TypeScript... is it necessary to have yet another language??
评论 #23642298 未加载
barbarbaralmost 5 years ago
It seems like a horrible idea to introduce this one off framework where ever you go. I feel sorry for the companies that has to carry the burden of the rewrite to something known. This should be used for a hobby at home.
edemalmost 5 years ago
Why would anyone write purescript when we have typescript?
评论 #23641300 未加载
评论 #23639454 未加载
评论 #23638725 未加载