const [working, setWorking] = useState(true);
const travel = () => setWorking(false);
const work = () => setWorking(true);
.
.
.
<TouchableOpacity activeOpacity={0.5} onPress={work}>
<Text style={{...styles.btnText, color : working ? 'white' : theme.grey}}>Work</Text>
</TouchableOpacity>
const target = { a: 1, b: 2}
const source = { c: 3, d: 4}
const returnedTarget = Object.assign(target, source);
// 출력
{ a: 1, b: 2, c: 3, d: 4 }
{ c: 3, d: 4 }
{ a: 1, b: 2, c: 3, d: 4 }
```
const addToDo = () => {
if(text === ""){
return
}
const newToDos = {...toDos, [Date.now()] : {text : text, working : working}}
setToDos(newToDos);
setText("")
}
```
<ScrollView>
{
Object.keys(toDos).map( (key) => {
return (
toDos[key].working === working ? (
<View key={key} style={styles.toDo}>
<Text style={styles.toDoText}>{toDos[key].text}</Text>
</View>
) : null
)
})
}
</ScrollView>