-1
export const HomeHeader = () => {

const filters = useSelector(state => state.filterReducer.category)
const loading = useSelector(state => state.filterReducer.loading)

const [filterArr, setFilter] = useState(filters)


const dispatch = useDispatch()

useEffect(() => {
  dispatch(loadingFilter())
  setFilter(filters)
}, [ filters, loading])



const {container,createPostWrapper, createIcon,
    createIconWrapper,filterWrapper} = styles


const handleFilter = (title) =>{
    dispatch(toggleFilter(title))
    console.log(filters)
}



if(loading){
    return <View><Text>Loading...</Text></View>
  } 

return (
    <View style={container}>
        <View style={createPostWrapper}>
            <CircleAvatar colorOfAvatar='#0067ff'>31</CircleAvatar>
            <TouchableOpacity style={createIconWrapper} >
                <Image style={createIcon} source={require('../../assets/create.png')}/>
            </TouchableOpacity>
        </View>
        <View style={filterWrapper}>
            {
                filterArr.map((item, index)  => 
                    <Filter 
                        key={index} 
                        selected={item.status} 
                        handleFilter={handleFilter} 
                        >
                            {item.title}
                    </Filter>
                )
            }
        </View>
    </View>
)

}

1 ответ 1

0

Используйте useSelector из библиотеки react-redux

1
  • 1
    Возможно у Вас есть пример применения? Так автору Вопроса и остальным участникам сообщества будет проще применить Ваш совет без дополнительного гугления.
    – V.March
    27 фев 2020 в 20:23

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.