29/04/2020
#javascript
iterables
iterables
- made a input / output kind of reactjs component
- react was throwing typeErrrors on my function because i forgot about JSON.parse for my incoming array which had been coerced to a string
- output with JSON.stringify
- iterables
- Object.entries(obj)=>
[[k,v],[k,v],..]
aka Map object -
{[k]:v,[k],v,..}
not iterable, but can use object entries on it - my fav form is
[{[k]:v},{[k]:v},..}]
, it is analog of a python dictionary object, is both iterable and referable. i dont like array keys - sometimes you have to push a new key value pair into an object and not an array because the keys are arbitrary, array indexes are not
[[0]v,[1]v,[2]v,..]
- object ↔ Map ↔ Array of Objects
- came across Symbol.iterator, analog is UUID
error handling in react
- error boundaries, analog of componentDidCatch
- typescript for larger projects, static typing similar to Java
code tag
in react JSX
- the tag wont work, you have to use CSS + selector + monospace font eg Courier
- template literals are useful, dont need to escape characters
{`string`} {`string ${expression} string`}
multiple inputs with single handler
- you have to use
e.target[name]=e.target.value
- use an array /object for the usestate
const [state,setState]=useState({name:value,name,value...})
setState{...state, [e.target.name]=e.target.value} - add names and values attributes to the input tags
- probably want to try that for multiple named buttons and use different functions, set an array of named functions
Comments