Skip to content

Tag: javascript

Why is useState not triggering re-render?

I’ve initialized a state that is an array, and when I update it my component does not re-render. Here is a minimal proof-of-concept: Based on this code, it seems that the input should contain the number 0 to start, and any time it is changed, the state should change too. After entering “02” …

Rename keys with ramda js

expected output: I’m thinking the renamed keys are defined in an object (but fine if there’s a better way to map them): How can I do this with Ramda? Something with R.map Answer There is an entry in Ramda’s Cookbook for this: But with the ubiquity of ES6, it’s pretty easy to write this…

Valid Braces – CodeWars Challenge

There is a challenge on codewars that asks you to check whether a string of parentheses, brackets, and curly braces is valid. A string of braces is considered valid if all braces are matched with the correct brace. I.e. “()” is valid and “[(])” is not. “(){}[]” is valid and…

How to merge two objects, overriding null values?

I’d like to merge two similar but not identical objects and override null values in one of them, if such exist. For example I’d have these two objects: And the effect of merge should be: In other words, the most important source of data in the merged object is obj2 but it lacks some properties fro…