A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
I'm building out a nodejs with reactjs front-end for an embedded application and was wondering how would be the best way to get a shop name in react pages ?
Hello there
To get the shop name in a React application using a session, you can follow these steps:
import axios from 'axios';
function MyComponent() {
const [shopName, setShopName] = useState(null);
useEffect(() => {
// Send a request to the server to retrieve the session data
axios.get('/api/session').then(response => {
// Update the shopName state variable with the shop name from the session data
setShopName(response.data.shopName);
});
}, []);
return (
<div>
{/* Render the shop name if it has been retrieved from the server */}
{shopName ? <p>Shop name: {shopName}</p> : <p>Loading shop name...</p>}
</div>
);
}
app.get('/api/session', (req, res) => {
res.json({ shopName: req.session.shopName });
});
hope this helps!