This if statement is checking the store id to pull in product information to the appropriate store but is not working correctly.
import { get } from 'lodash';
import { ProductContext } from '../../../context';
const SingleProductPage = (props) => {
const { match } = props;
const context = useContext(ProductContext);
const [loading, setLoading] = useState(true);
const awaitStore = async(companyID) => {
await context.setDetailStore(companyID)
await context.searchProductsById(companyID)
setLoading(false);
};
useEffect(() => {
const searchTerm = context.search;
if(searchTerm == '' && get(context, 'stores', []).length == 0){
const { params = {}} = match;
const { id } = params;
awaitStore(id)
}
}, [])
The if statement is not getting the appropriate id
context.js
const get = require('lodash/get')
const ProductContext = React.createContext();
searchStores = async(event) => {
const searchTerm = event.target ? event.target.value : event;
const { data } = await ApiUtil.get('/search/companies?searchterm=' + searchTerm);
const storeData = data && Array.isArray(data.stores) ? data.stores : [];
this.setStores(storeData);
}
Aucun commentaire:
Enregistrer un commentaire