1594201980
React’s useEffect hook has indeed made life a lot easier. But there are times when you would most certainly miss the fine-grained control class-based components give you over a component’s lifecycle. One such time is when you want to perform a side effect when a component’s state changes.
Of course, you can pass the state variable as a dependency into the useEffect hook but the problem is the callback function gets called during the initial render as well.
Take this little example. Let’s say I have an app that has a button. Once the button is clicked, I need to display a text that says “The button has been pressed!”. A simple way of doing this is to have a Boolean state value that will be set to true
once the button is clicked. The text can be displayed only if the Boolean value is true
.
However, for the sake of using the useEffect hook, let’s have two state values. Let me name the first state “press” and the second state “pressed”. Now, once the button is clicked, the press
state is set to true. Then let’s call the useEffect hook and pass a callback function that would set pressed
to true when press changes. The text should be shown only if pressed
is set to true.
export default function App() {
const [press, setPress] = useState(false);
const [pressed, setPressed] = useState(false);
useEffect(() => {
setPressed(true);
}, [press]);
return (
<div className="App">
{pressed && <div>The button has been pressed!</div>}
<button
onClick={() => {
setPress(true);
}}
>
Click!
</button>
</div>
);
But on running the app, you will realize that the text is shown even before the button is clicked. The reason? Well, useEffect’s callback function gets called not only when one of the dependencies changes but also during the initial render.
#react #front-end-development #frontend #reactjs
1594201980
React’s useEffect hook has indeed made life a lot easier. But there are times when you would most certainly miss the fine-grained control class-based components give you over a component’s lifecycle. One such time is when you want to perform a side effect when a component’s state changes.
Of course, you can pass the state variable as a dependency into the useEffect hook but the problem is the callback function gets called during the initial render as well.
Take this little example. Let’s say I have an app that has a button. Once the button is clicked, I need to display a text that says “The button has been pressed!”. A simple way of doing this is to have a Boolean state value that will be set to true
once the button is clicked. The text can be displayed only if the Boolean value is true
.
However, for the sake of using the useEffect hook, let’s have two state values. Let me name the first state “press” and the second state “pressed”. Now, once the button is clicked, the press
state is set to true. Then let’s call the useEffect hook and pass a callback function that would set pressed
to true when press changes. The text should be shown only if pressed
is set to true.
export default function App() {
const [press, setPress] = useState(false);
const [pressed, setPressed] = useState(false);
useEffect(() => {
setPressed(true);
}, [press]);
return (
<div className="App">
{pressed && <div>The button has been pressed!</div>}
<button
onClick={() => {
setPress(true);
}}
>
Click!
</button>
</div>
);
But on running the app, you will realize that the text is shown even before the button is clicked. The reason? Well, useEffect’s callback function gets called not only when one of the dependencies changes but also during the initial render.
#react #front-end-development #frontend #reactjs
1608796716
Hey there, you all know Binance… their smart chain and all the development happening there? Actually, I can barely recall any Binance-exclusive project developing there? Most adapted or added support for it out of the Ethereum ecosystem. We have a different approach. We believe the Huobi Eco Chain has incredible properties to serious challenge Ethereums’ prime stance in the DEFI space.
A couple of words about this incredible opportuniy….
The market for Decentralized Finance(DeFi) has been growing at an exponential rate since 2019. We have seen more than $14 billion total value locked within smart contracts with an annual growth rate of 1785.53%. With the growth of Uniswap DEX protocol, Compound Lending protocol, traditional financial instruments have been brought to Blockchain, innovative, disruptive, emerging to sophisticated ecosystems for everyone to use.
Huobi consistently ranks as one of the world’s top ten largest exchanges by trade volume. Huobi Eco Chain has opt to be as a better alternative to Ethereum or Binance Smart Chain. There is zero gas fee on Huobi Eco Chain, in turn incentivizing more users to transact on the chain. Furthermore, it is also EMV-compatible for developers to easy enter and applications to move to Huobi Eco Chain.
Introducing Fire Protocol….
Fireswap Protocol is the first infrastructure to Huobi Eco Chain, which helps onboard non-Huobi Chain assets via our cross-chain solutions, an integrated trading and money market with lending and borrowing services. FireSwap is committed to bridge the gap between centralized and decentralized finance by providing a one-stop financial solution exclusively on the Huobi Ecosystem: a protocol combination of UniSwap and Compound. This entails Basic functionalities such as of cross-chain asset wrapping, flash swap, liquidity mining, lending/borrowing pools, interest derivatives.
The DEX and the Lending platform works in conjunction, such as all tokens that are being traded or facilitated as liquidity provision, can also be used as collateral on the lending platform. With these collaterals, users can borrow other assets for trading, which in turn increase the trading volume. With the integrated DEX, the liquidation issue of lending / borrowing platform can also be solved, as we will automate the liquidation via selling the collateral on the AMM DEX directly (limited by the amount of liquidity available on the DEX), and in turn this will be a factor to consider for the collateralization ratio. FIRE token serve for incentive plans and governance voting to maintain the user ecosystem.
Distribution, Incentives and Proceeds
Fundraise : 10M
Valuation: 10%
For Sales: $1M
Hardcap
Vesting Periods:
Would you like to earn many tokens and cryptocurrencies right now! ☞ CLICK HERE
Looking for more information…
☞ Website
☞ Whitepaper
☞ Social Channel
☞ Message Board
☞ Documentation
Thank for visiting and reading this article! I’m highly appreciate your actions! Please share if you liked it!
#blockchain #bitcoin #fire protocol #fire
1603245600
Back in the day, rendering a website was simple. You needed a web server that served HTML files. Those were static sites. Then developers started using databases and authentication. To achieve that, they needed to manipulate the HTML file before serving it.
That’s how **server-side **rendering was born. Let’s fast forward until 2010, when Backbone got released. The front-end got richer and more complex. Then the era of client-side applications begin. Developers migrated their data and routing logic to the client side. They could, because Google “understood” JavaScript. The servers became slimmer, but the websites became more complex. Yet, recently server-side rendering became a trend again. All thanks to React and its server-side hydration feature.
Static sites are the simplest way to render a website. You code your website in HTML/CSS, and serve those files from a web server. This is the simplest way to render your website, but it comes with pros and cons.
Cons
Since they’re static, you cannot have dynamic data. To update the data on your static site, you need to edit your HTML files, and deploy them again.
That also means that your visitors won’t be able to “contribute” to the website data. They can’t leave comments, or create their own posts, or “like” your content.
Pros
But, since there’s no “computation” in static sites, they are the fastest to render. The server serves the HTML file, and the browser starts “drawing” immediately. This gives your website fast TTFB (time-to-first-byte) score.
Another benefit that static sites have is the ability to host them on CDNs. A CDN (content delivery network) is a network of servers distributed around the world. Meaning, your website will “live” on many servers at the same time. Also, CDNs are cheaper than dedicated servers!
They’re also more secure. There is no back-end. That means there’s less room for your site to suffer an attack, or your database to get compromised.
So, if you need to create a website that doesn’t update the data on a regular basis, static site might be the best for you. Your site will be fast, cheap, and more secure.
#server-side-rendering #spa #static-website #what-is-server-side-rendering #webdev #webdevelopment #nextjs #react-rendering
1625762940
Randal answers a late night question about how to get a callback from Stream.periodic at the start of the stream, and solves it, and solves it, and solves it, and solves it some more. Examples shown of “async*” and “yield*” and concatenating streams and managing generic types and extensions on core classes. [NOTE: not for beginners!] Thanks to Simon Lightfoot (@devAngelsLondon) for code review and suggesting a few things.
#stream.periodic #initial callback
1591118460
A very important piece of data I had to retrieve. Coming from the Future everything back there seemed uncomfortable and convoluted.
#callback #flutter #callback-hell