When a component re-renders with the same element type, the framework only touches the attributes that changed.
Write diffProps(oldProps, newProps) that returns { set, remove }. set is an object with every key whose value in newProps is new or different from oldProps, mapped to its new value. remove lists the keys that are in oldProps but not in newProps, sorted alphabetically (by character code).
Values are strings, numbers, or booleans, compared with ===.
Input: oldProps = {"class":"btn","disabled":true,"title":"Save"}, newProps = {"class":"btn primary","title":"Save"} Output: {"set":{"class":"btn primary"},"remove":["disabled"]}
class changed, title didn't, and disabled is gone.
Input: oldProps = {}, newProps = {"id":"x","tabIndex":0} Output: {"set":{"id":"x","tabIndex":0},"remove":[]}
Everything is new.
0 to 100 keys.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #710 Patch Changed Props. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.