我可以检查图像是否存在,如果存在,我可以将它们渲染出来,否则忽略图像吗?
Can i check if images exists and if they do, can i render them out, else ignore images?
我想对我的 API 请求进行排序。但是,当我第一次单击该选项时,什么也没有发生。当我单击其他选项时,仍然没有任何反应。当我第二次单击另一个选项时,它开始工作。
import { useEffect, useState } from "react";
//style
import styled from "styled-components";
import { motion } from "framer-motion";
import Header from "../components/Header";
//link
import { Link } from "react-router-dom";
//redux
import { useDispatch, useSelector } from "react-redux";
import { loadPreSortB } from "../actions/preSortAction";
//dropdown
const TabakMarken = () => {
//Fetch
const dispatch = useDispatch();
useEffect(() => {
dispatch(loadPreSortB(sortValue));
}, [dispatch]);
//get that data back
const { brand } = useSelector((state) => state.preSort);
//dropdown
const [sortValue, setSortValue] = useState("ASC");
const handleSortValue = (e) => {
setSortValue(e.target.value);
dispatch(loadPreSortB(sortValue));
};
return (
<SortenWrap>
<Header />
<SubHead>
<h2>Marke auswählen.</h2>
<select defaultValue="{sortValue}" onChange={handleSortValue}>
<option value="DESC">Alphabetisch A-Z</option>
<option value="ASC">Alphabetisch Z-A</option>
</select>
</SubHead>
...```
您正在根据本地状态 (sortValue) 的状态调度操作。为什么不删除那个状态而只写 dispatch(loadPreSortB(e.target.value))?我建议是因为,不能保证 sortValue 在调用 dispatch(sortValue) 时会发生变化。
我想对我的 API 请求进行排序。但是,当我第一次单击该选项时,什么也没有发生。当我单击其他选项时,仍然没有任何反应。当我第二次单击另一个选项时,它开始工作。
import { useEffect, useState } from "react";
//style
import styled from "styled-components";
import { motion } from "framer-motion";
import Header from "../components/Header";
//link
import { Link } from "react-router-dom";
//redux
import { useDispatch, useSelector } from "react-redux";
import { loadPreSortB } from "../actions/preSortAction";
//dropdown
const TabakMarken = () => {
//Fetch
const dispatch = useDispatch();
useEffect(() => {
dispatch(loadPreSortB(sortValue));
}, [dispatch]);
//get that data back
const { brand } = useSelector((state) => state.preSort);
//dropdown
const [sortValue, setSortValue] = useState("ASC");
const handleSortValue = (e) => {
setSortValue(e.target.value);
dispatch(loadPreSortB(sortValue));
};
return (
<SortenWrap>
<Header />
<SubHead>
<h2>Marke auswählen.</h2>
<select defaultValue="{sortValue}" onChange={handleSortValue}>
<option value="DESC">Alphabetisch A-Z</option>
<option value="ASC">Alphabetisch Z-A</option>
</select>
</SubHead>
...```
您正在根据本地状态 (sortValue) 的状态调度操作。为什么不删除那个状态而只写 dispatch(loadPreSortB(e.target.value))?我建议是因为,不能保证 sortValue 在调用 dispatch(sortValue) 时会发生变化。