Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Detect screen break point inside the component jsx itself

I have the following component:

    <Stack direction="row" spacing={2}>
      <Skeleton variant="rounded" animation="wave" sx={{ width: 1 }} />
      <Loading
        text="Loading..."
        sx={{ position: 'relative', background: 'none', color: 'grey' }}
        recommendedSolutions={
          <LoadingBtn
            onClick={refetch}
            variant="outlined"
            loadingIndicator="Refetching data..."
            loading={loading}
          >
            Try again
          </LoadingBtn>
        }
      />
    </Stack>

I want to be able to change the direction prop of the Stack component based on the screen breakpoint. The question is:

I can use the grid component to solve this problem as follows:

    <Grid container>
      <Grid item sx={{ display: { xs: 'none', md: 'block' } }}>
        <Stack direction="row" spacing={2}>
          <Skeleton variant="rounded" animation="wave" sx={{ width: 1 }} />
          <Loading
            text="Loading..."
            sx={{ position: 'relative', background: 'none', color: 'grey' }}
            recommendedSolutions={
              <LoadingBtn
                onClick={refetch}
                variant="outlined"
                loadingIndicator="Refetching data..."
                loading={loading}
              >
                Try again
              </LoadingBtn>
            }
          />
        </Stack>
      </Grid>
      <Grid item sx={{ display: { xs: 'block', md: 'none' } }}>
        <Stack direction="vertical" spacing={2}>
          <Skeleton variant="rounded" animation="wave" sx={{ width: 1 }} />
          <Loading
            text="Loading..."
            sx={{ position: 'relative', background: 'none', color: 'grey' }}
            recommendedSolutions={
              <LoadingBtn
                onClick={refetch}
                variant="outlined"
                loadingIndicator="Refetching data..."
                loading={loading}
              >
                Try again
              </LoadingBtn>
            }
          />
        </Stack>
      </Grid>
    </Grid>

but this makes me repeat similar code, is there a way I can do it within the direction prop of the Stack component itself? it's a tough task to write that much code

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!