Adventures in Coding


Thoughts on programming, web development, and tech

Refactoring a React App with Hooks, part 2

In my last blog post, I explained how to refactor a React app with hooks and began refactoring my own project American Ancestries. In this post I describe my completion of the refactoring, turning the the remaining class components into functional components, and also gettting rid of container components (which the creator of React now considers obsolete dut to the Hooks API).


Refactoring a project with React Hooks

The Hooks API in React is a relatively new feature that makes many older patterns of writing React code obsolete. So you may have been wondering, how do you rewrite your React code to take advantage of Hooks?


React hooks

Hooks in React are a new way to manage state, and reuse code that deals with state, without an excess of code. The Hooks API gives you a direct link into props, state, the context, and the lifecycle of component. You can directly “hook into” state and lifecycle, without using classes, eliminating a common source of complexity in React code. There are built in hooks in React, like useState or useEffect, and you can also write your own hooks.


Data Structures and Algorithms: Binary Search Trees, Part 2

In the previous post, I discussed how to implement binary search trees, and described how to insert a node and retrieve it from thre tree. In this post, I describe how to delete a node, and also how to iterate through a binary search tree.


Data Structures and Algorithms: Binary Search Trees, Part 1

Binary search trees are a common use of the tree data structure. Binary search, as you may recall, is an efficient way to search through data for a desired value. It takes logarithmic O(log n) time instead of slower linear O(n) time. It sometimes called the “dictionary method”: comparing what you are searching for, perhaps a word like “binary”, with the midpoint of a sorted data set, say “N” in the dictionary (note that a dictionary is sorted in alphabetical order). Then one uses the comparison to determine what half of the data set contains what you are looking for (“A-N”), and repeats the process until you have sufficiently narrowed it down. This process saves you, or the computer, from having to look through every element.