react native中使用tailwind并配置自动补全

javascript 复制代码
import { View, Text } from 'react-native';
import tw from 'twrnc';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-white dark:bg-black`}>
    <Text style={tw`text-md text-black dark:text-white`}>Hello World</Text>
  </View>
);

当然也支持条件变量

javascript 复制代码
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');
// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

重要的来了!配置vscode的补全

参考自React Native - Tailwind CSS autocomplete in VSCode for twrnc package

补全插件还是用的Tailwind CSS IntelliSense,需要添加vscode的配置并手动新建两个空文件

在下图添加

新建一个空文件tailwind.config.js

然后就可以了

相关推荐
沙漠8 小时前
ReactNative总结系列二 --- 小工具&小技巧md
react native
用户8876654266311 小时前
用 TanStack Table、React Query 和 shadcn/ui 搭一个可维护的数据表格架构
react.js·架构
zzqssliu15 小时前
Vue3 + Pinia 重构跨境代购前端:从taocarts的React方案学到的状态管理心得
前端·react.js·重构
humcomm16 小时前
FinClip vs React Native:两大跨平台方案的深度对比
javascript·react native·react.js
放下华子我只抽RuiKe516 小时前
FastAPI 全栈后端(一):为什么选择 FastAPI
前端·javascript·深度学习·react.js·机器学习·前端框架·fastapi
水云桐程序员16 小时前
Flutter与React Native的对比分析
flutter·react native·react.js
codefan※16 小时前
7 个Prompt 框架汇总:从 Chain of Thought 到 ReAct + PoT
前端·react.js·ai·llm·prompt·prompt工程·思维链
迁旭16 小时前
Claude Code /status 功能技术文档
前端·javascript·人工智能·react.js·机器学习·gpt-3·文心一言
星星~笑笑17 小时前
react Next.js oss上传 上传阿里云
javascript·react.js·阿里云·js